Mediaplayer exception - android

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

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.

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

Related

How to play video mp4 using intent from my android app? This is possible?

I need to play a mp4 video in my app, bat I want to use intent. Is this possible?
private void startTrailer(){
Uri contentUri = Uri.parse("android.resource://" + pkgName + "/" +R.raw.v01_homem_ferro_3);
Intent intent = new Intent( Intent.ACTION_VIEW );
intent.setDataAndType( contentUri, "video/mp4" );
context.startActivity( intent );
}
Exception: No Activity found to handle Intent.
Somebody had this issue before. Check these links and see if they give you a good starting point to solve the problem:
Android intent for playing video?
How to play a video (.mp4) from assets or raw folder with the video intent?
Please try this, Here strMyVideo is my filepath,
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(strMyVideo));
intent.setDataAndType(Uri.parse(strMyVideo), "video/mp4");
activity.startActivity(intent);

How to call the system default player to play the video?

I am developing an application. I want to realize a function like that I want to call the system default player.
After downloading the custom Audio or video file. Could it play using the system audio and video player in the program?
I want to create intent, and give the file path. Then call the system’s player.
any idears?
Try This
videourl="/sdcard/zzzz.3gp";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(videourl));
startActivity(intent);
String video = "http://www.nandudu.com/hls/course/video/2/test.m3u8";
Intent openVideo = new Intent(Intent.ACTION_VIEW);
openVideo.setDataAndType(Uri.parse(video), "video/*");
startActivity(openVideo);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(videourl));
startActivity(intent);
The above code should works for you to play video files
For kotlin:
val path: String = contentUri.getPath()
val file = File(path)
val intent = Intent(
Intent.ACTION_VIEW,Uri.fromFile(file))
intent.setDataAndType(Uri.parse(path), "video/*")
startActivity(intent)

Android:open default audio player

I am making an app in which I have to open default audio player. My code is as follows:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(songs.get(position));
//String introURI = "file:///sdcard/"+".mp3";
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
When the song is touched, the player gets open but it gives message that "this type of file is not supported".
The MediaPlayer class should be used when you want to implement your own media player. If you want to use an existing player, you'll have to launch the appropriate intent, for example:
Uri uri = Uri.parse("http://www.example.com/file.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
EDIT
How to get android local files uri
It will work. Try this
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(path);// path where your while is placed.For me like /storage/sdcard0/Media/audio/%2F1506580826442?alt=media&token=0e22f657-743c-4aed-9fed-48de69aced73.mp3
intent.setDataAndType(Uri.fromFile(file), "audio/*");
ActivityChatView.mContext.startActivity(intent);

startActivity on "file://" links crashes

I am trying to create program that simply opens file on sdcard. I tried opening mp3, mp4, and apk - the code bellow always crashes unexpectedly.
String _path = "file:///sdcard/1.apk";
Uri outputFileUri = Uri.parse(_path);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Market links also crashes. But when I set _path="http://google.com" - browser opens normally. How can I make this code work?
If you're trying to install the apk, you need to use the following:
String fileName = Environment.getExternalStorageDirectory() + "/1.apk";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
If you're trying to launch the app (after installing), then:
Intent intent = new Intent();
intent.setClassName("com.pkg.addr", "com.pkg.addr.MainActivity");
startActivity(intent);
If you're trying to launch a player to play the mp3 file:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse("file:///sdcard/1.mp3");
intent.setDataAndType(data,"audio/mp3");
startActivity(intent);
Hope that helps.

what is the issue i am Not able to open the native player to play the recorded file?

This is my code.what i am using?
Intent intent = new Intent(Intent.ACTION_DEFAULT);
intent.setDataAndType(Uri.parse(fileName), "audio/*");
startActivity(intent);
It is giving error
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/DCIM/Hitesh_2011-04-19Time10-55.amr typ=audio/* }
is there any permission to use native player.what is the issue?
plz help me.plz
Thanks in advance.
i dont get what do you mean by native player. but still this is the code that i have used to play a local file in the sdcard using the default player.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse("file://"+Environment.getExternalStorageDirectory()
.getAbsolutePath()+"/" + fileName);
String type = "audio/mp3";
intent.setDataAndType(data, type);
startActivity(intent);
Hope it helps and let me know the output of it.

Categories

Resources