简体   繁体   English

MediaPlayer在模拟器上运行,但不在设备上运行

[英]MediaPlayer working on emulator, but not on device

I am working on a radio app for Android and I've found a strange issue. 我正在为Android开发电台应用程序,但发现了一个奇怪的问题。 That's a part of the code: 这是代码的一部分:

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

The program works well on the emulator (2.2, 2.3), but when I try on my two devices (both Android 2.2) there is no audio. 该程序在模拟器(2.2、2.3)上运行良好,但是当我在两个设备(均为Android 2.2)上尝试时,都没有音频。 I've tried a lot of workarounds, but it seems so strange that Audio works on emulator, but not on devices. 我已经尝试了很多解决方法,但似乎很奇怪,音频无法在模拟器上运行,而可以在设备上运行。

PS: I've set Internet permissions PS:我已经设置了Internet权限

All the listiners are up (OnBufferingUpdateListener, OnCompletionListener, OnErrorListener, OnInfoListener, OnPreparedListener) On emulator I listen the music, but it gives error in logcat: emulator log 所有的监听器都启动了(OnBufferingUpdateListener,OnCompletionListener,OnErrorListener,OnInfoListener,OnPreparedListener)。在模拟器上,我听音乐,但是在logcat中出现错误: 仿真器日志

This is the error showed in logcat (on device): 这是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 -

What's the media type of the stream? 流的媒体类型是什么? Perhaps you're missing CODECs for that format on the production devices. 也许您在生产设备上缺少该格式的编解码器。

Honestly, the production devices tend have better CODECs than the emulators because the 2.x devices often have WMA as well as MP3 and MP4. 坦率地说,生产设备通常比仿真器具有更好的编解码器,因为2.x设备通常具有WMA以及MP3和MP4。 But maybe that breaks something. 但这也许会破坏一些东西。

If it's playlist format (eg m3u), or a compound format (atom? rss?, or some other format with multiple stream URLs in multiple formats in an envelope), maybe the production devices pick a format that doesn't stream so well. 如果是播放列表格式(例如m3u)或复合格式(atom?rss?或具有信封中多种格式的具有多个流URL的某种其他格式),则生产设备可能选择的流式格式不太好。 eg they pick a WMA stream, but find out that it has DRM only when they start decoding. 例如,他们选择了WMA流,但只有在开始解码时才发现它具有DRM。

Internet radio does often uses some kind of compound format. 互联网广播确实经常使用某种复合格式。 And they often put DRM on their WMA streams. 而且他们通常将DRM放在其WMA流中。 That would be a good candidate, actually. 实际上,那将是一个很好的候选人。

For what it's worth, 2.x streaming support is pretty weak. 就其价值而言,2.x流支持还很薄弱。 If you can crack the envelope and pick MP3 or MP4 instead of WMA you may do much better. 如果您可以破解信封并选择MP3或MP4而不是WMA,则可能会做得更好。

But the first question is: what's the format of the stream. 但是第一个问题是:流的格式是什么。

Also vaguely possible, I suppose: if your production devices are rooted, that disables decoding of DRM-protected files. 我想也可能是模糊的:如果您的生产设备已扎根,则将禁用对受DRM保护的文件的解码。 Try it with an unrooted device? 尝试使用无根设备吗?

Last possibility: 2.x devices use a variety of audio stacks. 最后一种可能性:2.x设备使用各种音频堆栈。 NVOMXPlayer doesn't look familiar. NVOMXPlayer看起来并不熟悉。 Are they Atrix devices? 它们是Atrix设备吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MediaPlayer可在模拟器上运行,但不能在android中的实际设备上运行 - MediaPlayer working on emulator, but not on actual device in android 声音(MediaPlayer)在模拟器上运行,但在实际的android设备上却无法运行 - Sound(MediaPlayer) working on emulator but not on a real android device MediaPlayer在模拟器中流式播放MP3,但不在设备上 - MediaPlayer streams MP3 in emulator, but not on device facebook 在模拟器上工作,而不是在设备上 - facebook working on emulator not on device alignParentBottom 在模拟器中工作但不在设备上 - alignParentBottom working in emulator but not on device 广播接收器在模拟器中工作,但不在设备中工作 - Broadcastreceiver working in emulator but not in device 动画只能在模拟器上运行,而不能在设备上运行 - Animations working on emulator but not on device 在设备上也不在模拟器上不起作用 - not working on device and not on emulator mediaplayer IllegalStateException在模拟器上没有错误,但有时在真实设备上崩溃 - mediaplayer IllegalStateException no errors on emulator but sometimes crashed on real device KeyListener可在模拟器上运行,但不能在设备上运行 - KeyListener working on emulator but not working on device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM