Call default media player with URI on Android

I found this code:

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

Sound is played using the default media player. I want to call the same media player with a URI that contains the url.

How do I target my default player?

+3
source share
1 answer

You also need to install mimetype.

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);
+8
source

Source: https://habr.com/ru/post/1764424/


All Articles