Reputation: 293
I am trying to play audio with the ACTION_VIEW intent, but regardless on what type of sound file (.mp3, .3gpp etc.) I always get the same error:
E/AndroidRuntime(3007): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/recording-23363382.3gpp typ=audio/3gpp }
My code:
Firstly here is where I launch the activity:
case R.id.largeThumbnailText:
media_column_index = mediacursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
mediacursor.moveToPosition(lastClicked);
mediaFileUri = Uri.parse(mediacursor.getString(media_column_index));
media_column_index = mediacursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE);
String mime = mediacursor.getString(media_column_index);
Intent playAudioIntent = new Intent();
playAudioIntent.setAction(Intent.ACTION_VIEW);
playAudioIntent.setDataAndType(mediaFileUri, mime);
startActivity(playAudioIntent);
break;
This is where I initiate the mediacursor:
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.MIME_TYPE };
mediacursor = getActivity().managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null,
null, null);
I do the same thing with video, so I don't see where the problem is. Might be worth mentioning that this is all done from within a fragment.
Forgot to mention I'm testing it on a HTC Sensation (android 2.3.4)
Appreciate any suggestions
Upvotes: 3
Views: 7409
Reputation: 13327
common error when setting wrong mime type in the intent take this example check if it is audio/mp3
to play mp3 audios
Uri data = Uri.parse("file:///sdcard/abc_xyz.mp3");
intent.setDataAndType(data,"audio/mp3");
startActivity(intent);
Upvotes: 1
Reputation: 5759
Instead of your code
Intent playAudioIntent = new Intent();
playAudioIntent.setAction(Intent.ACTION_VIEW);
playAudioIntent.setDataAndType(mediaFileUri, mime);
startActivity(playAudioIntent);
Try something like this:
String movieurl = Environment.getExternalStorageDirectory() + "/Videos/Wildlife.wmv";
Intent playAudioIntent = new Intent(Intent.ACTION_VIEW);
playAudioIntent .setDataAndType(Uri.parse(movieurl), "video/*");
Upvotes: 1