Note that there are some explanatory texts on larger screens.

plurals
  1. POMediaPlayer stream cuts out randomly
    primarykey
    data
    text
    <p>I'm trying to stream 1.5-4 hour audio files from a URL. I have my service run when a link to an mp3 file is clicked in the browser and I use this code to play it:</p> <pre><code> String sData = intent.getDataString(); if (sData != null &amp;&amp; sData.startsWith("http:") &amp;&amp; sData.endsWith(".mp3")) { if (p_oPlayer == null) { CreateMediaPlayer(); // sets p_oPlayer = new MediaPlayer() and creates callbacks for OnPreparedListener, OnErrorListener, OnInfoListener &amp; OnCompletionListener } else { if (p_oPlayer.isPlaying()) p_oPlayer.stop(); p_oPlayer.reset(); } // The next 5 lines are just to make a title out of a filename String sFile = ""; Pattern p = Pattern.compile("([^/]*)\\.mp3"); Matcher m = p.matcher(sData); if (m.find()) sFile = m.group(1).replace("%20", " "); p_oPlayer.setDataSource(sData); p_oPlayer.prepareAsync(); // OnPreparedListener callback just calls start() on the MediaPlayer Intent i = new Intent(this, Main.class); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pIntent = PendingIntent.getActivity(this, 0, i, 0); Notification notice = new Notification(R.drawable.icon2, "WFKO stream is playing", System.currentTimeMillis()); notice.setLatestEventInfo(this, "WFKO Radio", sFile, pIntent); notice.flags |= Notification.FLAG_NO_CLEAR; startForeground(myID, notice); } </code></pre> <p>So you can see I'm using a foreground service to the Android system knows not to trash the service unless its absolutely necessary. The problem is the streams randomly cut out 10-20 minutes into playing, and it's not just hitting a certain chunk of data and crashing because if I play the same stream multiple times it will cut out at different places each time. OnCompletionListener, OnErrorListener, and OnInfoListener all do nothing. I just created them and put breakpoints on them to try to see what's happening. When the stream cuts out it goes straight to OnCompletionListener. It never calls the info or error methods.</p> <p>The notification for the foreground service stays in the notification bar when the stream stops so I'm pretty sure the Android system is murdering it. I don't know where to go from here.</p> <p>Does anyone have any ideas what could be wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload