Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Android 调用系统播放器

1、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);相关阅读:Android本地视频播放器开发 http://www.linuxidc.com/Linux/2013-06/85955.htmAndroid 音乐播放器中播放模式的设计 http://www.linuxidc.com/Linux/2013-05/84576.htmAndroid应用开发之简易视频播放器 http://www.linuxidc.com/Linux/2012-03/55565.htmAndroid应用开发之简易音频播放器 http://www.linuxidc.com/Linux/2012-03/55566.htmAndroid音乐播放器(改进版) http://www.linuxidc.com/Linux/2012-02/55387.htmAndroid:一步一步实现音乐播放器 http://www.linuxidc.com/Linux/2012-02/55382.htm更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11