views:

91

answers:

1

I found this code:

Uri u = 
            Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, 
            "1"); 
            i.setData(url); 
            startActivity(i); 

That plays a sound with the default media player. I want to call the same media player with a URI that contains a URL.

How can I target the default player?

A: 

You need to set mimetype as well.

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

bhups