简体   繁体   中英

Audio Streaming OutOfMemoryError

I am trying to stream an audio content (AAC) from server. The player starts without any problem, and after some time throws OutOfMemoryError. I think I need to buffer the audio. Any one please guide me to implement (or get rid-of this error) buffering.

Here is my code.

   `HttpConnection c = null; 
    InputStream is = null;
    try {
        c = (HttpConnection) Connector.open(streamURL, 
                Connector.READ_WRITE);
        int rc = c.getResponseCode(); 
        System.out.println("Response Code " + rc);

        if (rc != HttpConnection.HTTP_OK) {
            showAlert("Server error returned");

        } else {
            playerForm.append("openInputStream");
            is = c.openInputStream();
            player = Manager.createPlayer(is, "audio/aac");
            player.realize();

             // get volume control for player and set volume to max
            VolumeControl vc = (VolumeControl) player.getControl("VolumeControl");
            if(vc != null)
            {
              vc.setLevel(100);
            }


            player.prefetch();

            player.start();
        } 
    } catch (Exception f) {
        playerForm.append("Exception in player " + f.getMessage() + "\n");
    } finally { // Aufräumarbeiten ausführen
        if (is != null)
            try {
                is.close();                 
            } catch (IOException e) {
            }
        if (c != null)
            try {
                c.close();                  
            } catch (IOException e) {
            }
    }`

Thanks in advance.

Regards Anish.

代替catch中的Exception,只需使用Throwable类,它将处理OutOfMemoryError

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM