设为首页 加入收藏

TOP

Android 调用系统播放器
2014-11-24 02:53:30 来源: 作者: 【 】 浏览:0
Tags:Android 调用 系统 播放器

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);


2、Android调用系统视频播放器


方法一;
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);


相关阅读:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇newLISP 遍历目录树,清理编译目录 下一篇arm_linux_device_mem内存映射

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: