Sreedev
Sreedev

Reputation: 6653

Mediaplayer exception

Intent intent1 = new Intent( android.provider.MediaStore.INTENT_ACTION_MUSIC_PLAYER) .setData(selectedImageUri);

i want to play a media file using android default media player but its not working in devices showing

ActivityNotFoundException

.can any one help me to correct it.i am stuck here

Upvotes: 1

Views: 192

Answers (2)

Sreedev
Sreedev

Reputation: 6653

String extension = MimeTypeMap
                        .getFileExtensionFromUrl(selectedImagePath);
                String mimeType = MimeTypeMap.getSingleton()
                        .getMimeTypeFromExtension(extension);
                Intent mediaIntent = new Intent(Intent.ACTION_VIEW);
                mediaIntent.setDataAndType(Uri.parse(selectedImagePath),
                        mimeType);
                startActivity(mediaIntent);

I used this code and i got my output.

Upvotes: 4

Andro Selva
Andro Selva

Reputation: 54322

Maybe this will help you. The following is the piece which I use and it works fine. Pass the url to your default media Player and from there it will take care of it.

                  Uri myUri = Uri.parse( //your url);
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW); 
             intent.setDataAndType(myUri, "audio/*"); 
             startActivity(intent);

Upvotes: 0

Related Questions