1

I am making an app in which I have to open default audio player. My code is as follows:

Intent intent = new Intent();           
intent.setAction(android.content.Intent.ACTION_VIEW);  
File file = new File(songs.get(position));  
//String introURI = "file:///sdcard/"+".mp3";  
intent.setDataAndType(Uri.fromFile(file), "audio/*");  
startActivity(intent);

When the song is touched, the player gets open but it gives message that "this type of file is not supported".

Aditya1510
  • 874
  • 1
  • 14
  • 31
  • possible duplicate of [Android launching music player using intent](http://stackoverflow.com/questions/3114471/android-launching-music-player-using-intent) – MByD Apr 05 '12 at 11:38
  • This is not duplicate because the link given by you shows list of all songs in sdcard rather than playing specific song – Aditya1510 Apr 05 '12 at 12:08
  • And moreover BInyamin Sharet, link given by you plays no file – Aditya1510 Apr 05 '12 at 12:15

2 Answers2

1

The MediaPlayer class should be used when you want to implement your own media player. If you want to use an existing player, you'll have to launch the appropriate intent, for example:

Uri uri = Uri.parse("http://www.example.com/file.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

EDIT

How to get android local files uri

Nimit
  • 1,694
  • 3
  • 22
  • 33
1

It will work. Try this

    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(path);// path where your while is placed.For me like /storage/sdcard0/Media/audio/%2F1506580826442?alt=media&token=0e22f657-743c-4aed-9fed-48de69aced73.mp3
    intent.setDataAndType(Uri.fromFile(file), "audio/*");
    ActivityChatView.mContext.startActivity(intent);
NipunPerfect
  • 125
  • 1
  • 7