Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid MediaPlayer works fine in Custom audio Streaming application up to Android 2.1 but not in higher versions
    text
    copied!<p><strong>EDIT:</strong></p> <p><a href="https://stackoverflow.com/questions/8681550/android-2-2-mediaplayer-is-working-fine-with-one-shoutcast-url-but-not-with-the">Android 2.2 MediaPlayer is working fine with one SHOUTcast URL but not with the other one</a></p> <p>I need to play audio files from external URLs(shoutcast stream). Currently the audio files are downloaded incrementally &amp; are played as soon as we get enough audio in phone local temporary storage. i am using the <a href="http://www.java2s.com/Open-Source/Android/App/ijoker/cn/edu/xmu/software/streamradio/media/StreamingMediaPlayer.java.htm" rel="nofollow noreferrer">StreamingMediaPlayer class</a>.</p> <p>Check this piece of code:</p> <pre><code> private MediaPlayer createMediaPlayer(File mediaFile) throws IOException { MediaPlayer mPlayer = new MediaPlayer(); //example of mediaFile =/data/data/package/cache/playingMedia0.dat FileInputStream fis = new FileInputStream(mediaFile); mPlayer.setDataSource(fis.getFD()); mPlayer.prepare(); return mPlayer; } </code></pre> <p><strong>Current status:</strong></p> <p>1- It works fine from Android 1.6 to 2.1 but not in the higher versions like Android 2.2. </p> <p>2- The "mPlayer.setDataSource(fis.getFD())" is the line which throws the error. </p> <p>3- The error is "Unable to to create media player"</p> <p><strong>Other Solution tried:</strong></p> <p>I tried below alternate solution but nothing worked so far.</p> <p><a href="https://stackoverflow.com/questions/8681550/android-2-2-mediaplayer-is-working-fine-with-one-shoutcast-url-but-not-with-the">Android 2.2 MediaPlayer is working fine with one SHOUTcast URL but not with the other one</a></p> <p><strong>What i am looking for?</strong></p> <p>My goal is to have a peace of code which can work on Android 2.1 &amp; higher. </p> <p><strong>This issue is also discussed here:</strong></p> <p>1- <a href="http://code.google.com/p/android/issues/detail?id=9787" rel="nofollow noreferrer">Inconsistent 2.2 Media Player Behavior</a></p> <p>2- <a href="https://stackoverflow.com/a/4392663/265167">android code for streaming shoutcast stream breaks in 2.2</a></p> <p>3- This issue is also discussed in a lot of questions on this site, but i found the answer no where.</p> <p>4- <a href="http://markmail.org/message/oztg7eb2entfdu3i" rel="nofollow noreferrer">markmail.org</a></p> <p><strong>LogCat trace:</strong></p> <pre><code>Unable to to create media player Error copying buffered conent. java.lang.NullPointerException com.ms.iradio.StreamingMediaPlayer.startMediaPlayer(StreamingMediaPlayer.java:251) com.ms.iradio.StreamingMediaPlayer.access$2(StreamingMediaPlayer.java:221) com.ms.iradio.StreamingMediaPlayer$2.run(StreamingMediaPlayer.java:204) android.os.Handler.handleCallback(Handler.java:587) android.os.Handler.dispatchMessage(Handler.java:92) android.os.Looper.loop(Looper.java:123) android.app.ActivityThread.main(ActivityThread.java:3683) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:507) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) dalvik.system.NativeStart.main(Native Method) </code></pre>
 

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