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".

  • 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 –  Apr 05 '12 at 12:08
  • And moreover BInyamin Sharet, link given by you plays no file –  Apr 05 '12 at 12:15

2 Answers2

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
0

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,714
  • 3
  • 22
  • 33
  • also refer this link http://www.helloandroid.com/tutorials/how-play-video-and-audio-android – Nimit Apr 05 '12 at 11:42
  • You are giving some link but if i want to mp3 files from sdcard, how to give that in Uri –  Apr 05 '12 at 12:07
  • I want to access all amr files from sdcard –  Apr 06 '12 at 04:47
  • sd card contain dynamic mp3 files so uri has to be set in some dynamic way? –  Apr 06 '12 at 05:41