我正在爲android安裝一個電臺應用程序,並且發現了一個奇怪的問題。這是代碼的一部分:Android:在模擬器上工作的MediaPlayer,但不在設備上
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:我已經設置網絡權限
編輯:所有listiners均達到(OnBufferingUpdateListener,OnCompletionListener,OnErrorListener,OnInfoListener,OnPreparedListener)在模擬器我聽音樂,但它在logcat中給出了錯誤:emulator log
這表明在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 -
什麼返回「isPlaying()」?你的流是否播放?確保你設置了音量。您還可以註冊一個偵聽器來檢查是否存在警告或錯誤「setOnInfoListener()」。 –
在設備上它給了我一個解碼器錯誤,在模擬器工作。我真的不明白髮生了什麼:| – Stefano
哪個解碼錯誤? –