Android: playing a song file using default music player

前端 未结 2 1471
攒了一身酷
攒了一身酷 2021-01-15 14:39

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

 Intent intent = new Intent(Intent.ACTION_VIEW);
 MimeType         


        
2条回答
  •  耶瑟儿~
    2021-01-15 15:01

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

提交回复
热议问题