2010-06-24 4 views

답변

79

이렇게하는 방법이 하나 있습니다.

Intent intent = new Intent(); 
intent.setAction(android.content.Intent.ACTION_VIEW); 
File file = new File(YOUR_SONG_URI); 
intent.setDataAndType(Uri.fromFile(file), "audio/*"); 
startActivity(intent); 
단순히 음악 플레이어를 실행하려면
+0

작품 : – Calvin

+0

미디어 플레이어를 확인하는 방법은 응용 프로그램이 넥서스 6에서 작동하지 않는 장치 –

+0

에 availbe 여부입니다 오디오 시도 @nbarraille – nbarraille

19

할 :

Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER); 
startActivity(intent); 
+1

이것은 SDK API 레벨 8 이상에서만 작동합니다. – grzaks

+0

plz 위의 코드를 작성한 후에 모든 일을해야한다는 것을 알려주시겠습니까? 귀하의 도움은 나에게 유용 할 것입니다. –

+4

이 작업에는 CATEGORY_APP_MUSIC이 (가) 사용되지 않습니다. –

0

당신은이 일을 시도 할 수 있습니다.

Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 
2
  if (Build.VERSION.SDK_INT >= 24) { 
       try { 
        Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure"); 
        m.invoke(null); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
      } 
      Intent intent = new Intent(); 
      intent.setAction(android.content.Intent.ACTION_VIEW); 
      File file = new File(YOUR_SONG_URI); 
      intent.setDataAndType(Uri.fromFile(file), "audio/*"); 
      startActivity(intent); 
0

은 기본 오디오 플레이어를 달성 할 수있는 방법이 될 것입니다 그러나 그 장치와 OS에만 적용됩니다.

이 코드 스 니펫으로 기본 오디오 플레이어를 사용할 수 있습니다. 마법처럼

try 
    { 
    Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW); 
    File file = new File("audiofilepath"); 
    String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString()); 
    String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); 
    myIntent.setDataAndType(Uri.fromFile(file),mimetype); 
    startActivity(myIntent); 
    } 
    catch (Exception e) 
    { 
     e.printStackTrace(); 
    } 
관련 문제