安卓:使用默认的音乐播放器播放歌曲文件 [英] Android: playing a song file using default music player

查看:416
本文介绍了安卓:使用默认的音乐播放器播放歌曲文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用默认的媒体播放器播放媒体。我可以用下面的code执行

Is there a way to play a media with the default media player. I can do with the following code

 Intent intent = new Intent(Intent.ACTION_VIEW);
 MimeTypeMap mime = MimeTypeMap.getSingleton();
 String type = mime.getMimeTypeFromExtension("mp3");
 intent.setDataAndType(Uri.fromFile(new File(songPath.toString())), type);
 startActivity(intent);

但是,这将启动一个播放机用较少的控制,并且不能将其推到背景。 我可以启动播放器的默认媒体播放器?

But this launches a player with less controls and can't push it to the background. Can I launch the player with the default media player?

THX! 拉胡尔。

推荐答案

试试下面的code :::

Try the below code:::

   Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);  
   File file = new File(songPath.toString());  
   intent.setDataAndType(Uri.fromFile(file), "audio/*");  
   startActivity(intent);

更新::试试这个也是

Updated:: Try this also

   Intent intent = new Intent();  
   ComponentName comp = new ComponentName("com.android.music", "com.android.music.MediaPlaybackActivity");
   intent.setComponent(comp);
   intent.setAction(android.content.Intent.ACTION_VIEW);  
   File file = new File(songPath.toString());  
   intent.setDataAndType(Uri.fromFile(file), "audio/*");  
   startActivity(intent);

这篇关于安卓:使用默认的音乐播放器播放歌曲文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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