Android:打开默认音频播放器 [英] Android:open default audio player

查看:49
本文介绍了Android:打开默认音频播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序,我必须在其中打开默认音频播放器.我的代码如下:

I am making an app in which I have to open default audio player. My code is as follows:

Intent intent = new Intent();           
intent.setAction(android.content.Intent.ACTION_VIEW);  
File file = new File(songs.get(position));  
//String introURI = "file:///sdcard/"+".mp3";  
intent.setDataAndType(Uri.fromFile(file), "audio/*");  
startActivity(intent);

触摸歌曲时,播放器打开,但提示不支持这种类型的文件".

When the song is touched, the player gets open but it gives message that "this type of file is not supported".

推荐答案

当您想要实现自己的媒体播放器时,应该使用 MediaPlayer 类.如果要使用现有播放器,则必须启动相应的意图,例如:

The MediaPlayer class should be used when you want to implement your own media player. If you want to use an existing player, you'll have to launch the appropriate intent, for example:

Uri uri = Uri.parse("http://www.example.com/file.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

编辑

如何获取android本地文件uri

这篇关于Android:打开默认音频播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆