Android(安卓)调用系统播放器
16lz
2022-04-19
1、调用系统音乐播放器
private void playAudio(String audioPath){ Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(audioPath), "audio/mp3"); intent.setComponent(new ComponentName("com.android.music","com.android.music.MediaPlaybackActivity")); startActivity(intent); }
private void playAudio(String audioPath){Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(audioPath), "audio/mp3"); intent.setComponent(new ComponentName("com.android.music","com.android.music.MediaPlaybackActivity")); startActivity(intent);}或者
Intent it = new Intent(Intent.ACTION_VIEW); it.setDataAndType(Uri.parse("/sdcard/111.mp3"), "audio/mp3"); startActivity(it);
Intent it = new Intent(Intent.ACTION_VIEW);it.setDataAndType(Uri.parse("/sdcard/111.mp3"), "audio/mp3");startActivity(it);
方法一;
private void playVideo(String videoPath){ Intent intent = new Intent(Intent.ACTION_VIEW); String strend=""; if(videoPath.toLowerCase().endsWith(".mp4")){ strend="mp4"; } else if(videoPath.toLowerCase().endsWith(".3gp")){ strend="3gp"; } else if(videoPath.toLowerCase().endsWith(".mov")){ strend="mov"; } else if(videoPath.toLowerCase().endsWith(".wmv")){ strend="wmv"; } intent.setDataAndType(Uri.parse(videoPath), "video/"+strend); startActivity(intent); }
或者
Intent it = new Intent(Intent.ACTION_VIEW); it.setDataAndType(Uri.parse("/sdcard/1122.mp4"), "video/mp4"); startActivity(it);
播放来自网络多媒体文件
String extension = MimeTypeMap.getFileExtensionFromUrl(url);String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);Intent mediaIntent = new Intent(Intent.ACTION_VIEW);mediaIntent.setDataAndType(Uri.parse(url), mimeType);startActivity(mediaIntent);
更多相关文章
- android 调用相册里的图片并返回
- Android(安卓)– Multithreading in a UI environment
- android 异步下载图片
- Android中获取指定日期是星期几
- android 常用代码
- android O 手机关机流程与时间
- Android(安卓)Surface 介绍
- Android调用自定义Dialog中的控件
- android 调用系统日历