我正在开发适用于 Android 的广播应用程序,但发现了一个奇怪的问题。这是代码的一部分:
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setVolume(1, 1);
try {
mediaPlayer.setDataSource(url);
mediaPlayer.setOnPreparedListener(
mediaPlayer.prepareAsync(); // prepare async to not block main thread
该程序在模拟器(2.2、2.3)上运行良好,但是当我在我的两台设备(均为 Android 2.2)上尝试时,没有音频。我尝试了很多解决方法,但音频在模拟器上工作,但在设备上却不行,这似乎很奇怪。
PS:我已经设置了上网权限
所有的侦听器都已启动(OnBufferingUpdateListener、OnCompletionListener、OnErrorListener、OnInfoListener、OnPreparedListener)在模拟器上我听音乐,但它在 logcat 中给出错误:模拟器日志
这是 logcat 中显示的错误(在设备上):
E/OMXPlayer( 953): Creating new NVOMXPlayer: 0x9c1a8
E/OMXPlayer( 953): onFirstRef ++
E/OMXPlayer( 953): onFirstRef --
E/OMXPlayer( 953): setdatasource ++
E/OMXPlayer( 953): 0x9c1a8 setDataSource url=http://XXXXXX:8000
E/OMXPlayer( 953): render thread(10972) started: 0x9c1a8
E/OMXPlayer( 953): STATE_PREPARING - signal wait 0x9c1a8
E/OMXPlayer( 953): prepareAsync: 0x9c1a8
E/OMXPlayer( 953): STATE_PREPARING - signal rx'd 0x9c1a8
E/OMXPlayer( 953): prepare 0x9c1a8
E/OMXPlayer( 953): 0x9c1a8 Creating player for: http://XXXXX:8000
D/ ( 961): NVRM_DAEMON(803): rt_exist=2, add client ref
D/ ( 953): NvMMSetUserAgentString:: Len: 49: String: User-Agent: (NvMM Client v0.1; Linux;Android 2.2)
D/ ( 953): connect cancelled
D/ ( 953): connect cancelled
D/ ( 953): connect cancelled
D/ ( 953): connect cancelled
D/ ( 953): connect cancelled
D/ ( 953): connect cancelled
D/ ( 953): connect cancelled
D/ ( 953): Event_BlockError from 13SuperParser : Error code - 4
D/ ( 953): Graph_EventHandler: ERROR for READER [0x80001005]
D/ ( 953): Graph_EventHandler: ERROR for READER [0x80001005]
E/MediaPlayer(10958): error (1, 0)
E/ (10958): Prepare failed.: status=0x1
E/ (10958): java.io.IOException: Prepare failed.: status=0x1
E/ (10958): at android.media.MediaPlayer.prepare(Native Method)
E/ (10958): at app.relax.com.StreamingMediaPlayer.listen(StreamingMediaPlayer.java:64)
E/ (10958): at app.relax.com.StreamingMediaPlayer.startListening(StreamingMediaPlayer.java:74)
E/ (10958): at app.relax.com.StreamingMediaPlayer.access$0(StreamingMediaPlayer.java:70)
E/ (10958): at app.relax.com.StreamingMediaPlayer$1.run(StreamingMediaPlayer.java:51)
E/ (10958): at java.lang.Thread.run(Thread.java:1096)
E/OMXPlayer( 953): prepare 0x9c1a8 exit with error
E/OMXPlayer( 953): Error in prepare
E/OMXPlayer( 953): Worker Thread Exit -