尝试播放某些设备上的MP3 ActivityNotFoundException设备、ActivityNotFoundException

2023-09-04 03:51:10 作者:章鱼小肉丸

我从银河ACE设备越来越崩溃报告试图播放MP3文件。

I'm getting crash reports from a Galaxy Ace device trying to play mp3 files.

来自服务器的音频会经常来的MP3。

The audio from the server will always come as mp3.

下面是我的code:

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

下面是例外:

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 }

有什么不好呢?所有设备都应该能够在默认情况下播放MP3,不是吗?

What is wrong with that? All devices are supposed to be able to play mp3 by default, no?

推荐答案

显然,一些设备不具有可以处理播放MP3文件的活动。这些设备应该能够播放MP3文件,但没有活动处理的意图。你得写一个自己并设置意图过滤说你的活动可以处理播放MP3。

Apparently some devices don't have an activity that can handle playing mp3 files. Those devices should be able to play mp3 files, but there is no activity to handle the intent. You gotta write one yourself and set the intent-filter to say your activity can handle playing mp3.

试试这个,看看是否有一个音乐播放器。

Try this and see if there is a music player.

Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
startActivity(intent);
 
精彩推荐