Audio Streaming OutOfMemoryError

155 views Asked by At

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.

1

There are 1 answers

0
Amarnath Baitha On

Instead of Exception in catch just use Throwable class it will handle OutOfMemoryError