rah*_*hul 2 media android android-mediaplayer
有没有办法使用默认媒体播放器播放媒体.我可以使用以下代码
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);
Run Code Online (Sandbox Code Playgroud)
但是这会启动一个控制较少的玩家,并且无法将其推向后台.我可以使用默认媒体播放器启动播放器吗?
谢谢!拉胡尔.
试试以下代码:::
Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
File file = new File(songPath.toString());
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
更新::也尝试这个
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6608 次 |
| 最近记录: |