3

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?

1 Answer 1

8

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.