Search code examples
androidexceptionmedia-player

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


Solution

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