简体   繁体   English

尝试在某些设备上播放 mp3 ActivityNotFoundException

[英]Trying to play mp3 ActivityNotFoundException on certain devices

I'm getting crash reports from a Galaxy Ace device trying to play mp3 files.我收到来自试图播放 mp3 文件的 Galaxy Ace 设备的崩溃报告。

The audio from the server will always come as mp3.来自服务器的音频将始终以 mp3 格式提供。

Here's my code:这是我的代码:

Intent intentaudio = new Intent();
intentaudio.setAction(Intent.ACTION_VIEW);
intentaudio.setDataAndType(URL_OF_MY_MP3_FILE, "audio/mp3");

Here's the exception:这是一个例外:

android.content.ActivityNotFoundException: No Activity found to handle Intent {
  act=android.intent.action.VIEW dat=http://mymediaserver.com/8/0_rwtel7ii.mp3 typ=audio/mp3 }

What is wrong with that?那有什么问题? All devices are supposed to be able to play mp3 by default, no?默认情况下,所有设备都应该能够播放 mp3,不是吗?

Apparently some devices don't have an activity that can handle playing mp3 files.显然,某些设备没有可以处理播放 mp3 文件的活动。 Those devices should be able to play mp3 files, but there is no activity to handle the intent.这些设备应该能够播放 mp3 文件,但没有活动来处理意图。 You gotta write one yourself and set the intent-filter to say your activity can handle playing mp3.您必须自己编写一个并设置意图过滤器以说明您的活动可以处理播放 mp3。

Try this and see if there is a music player.试试这个,看看是否有音乐播放器。

Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
startActivity(intent);

You'll get this error if your device doesn't have an app that supports this format.如果您的设备没有支持此格式的应用程序,您将收到此错误。 So, I recommend you surround this code with a try/catch .所以,我建议你用try/catch包围这段代码。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM