I have app where I have url of media file.
I wish if I could start Music and Video app and play file.
Is there any chance to do that.
I dont want to write my own media player app.
Create an ACTION_VIEW intent with the path to your media file and include the type of media you want to play.
String audioPath = "path/to/audio.mp3";
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
// set the data and type, for movies this would be video/*
intent.setDataAndType(Uri.parse(audioPath), "audio/*");
getContext().startActivity(intent);
You don't have to set the type, but I would suggest doing so. Setting the type will limit the activities to activities that know how to handle the given type.
Related
My app show list of song from sd card. I want to be able to play the song on the default player. I've got all the data about the song: id, title, album, artist, path...
Is there a way to launch the default player to play the song?
What I've tried:
Using Intent.CATEGORY_APP_MUSIC. I can launch the default player, but can't set the song.
Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_MUSIC) open the default music app.
Howeverintent.setData(Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id)) throws exception that intent not found.
Using deprecated MediaStore.INTENT_ACTION_MUSIC_PLAYER. Activity not found.
Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER).setDataAndType(Uri.fromFile(songFile), "audio/*")
Using INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH. Launch the search, but not the song, says couldn't prepare mix on Play music. However, it works from Google now, so it may be the key.
Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH).putExtra(SearchManager.QUERY, name)
Using ACTION_VIEW. it works but it launch a compact version of the player, and I want the full player.
Note: I want to launch External player, not in my app.
Update: Looks like Google Now hardcoded Play Music and Youtube support.
If you would like to start the default music player app on the device, should try this:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
it is launching a compact version for playing as that app has implemented it that way,
you can find many 3rd party app that open the full app with
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
as you already tried this
Try with something simple like this:
MediaPlayer mp = new MediaPlayer();
mp.setLooping(true);
try {
mp.setDataSource(mFile); //mFile is the path to your mp3 file
} catch (Exception e) {
e.printStackTrace();
}
try {
mp.prepare();
} catch (Exception e) {
e.printStackTrace();
}
mp.start();
And one more example with MadiaPlayer and file saved in res/raw/ directory:
MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1);
mediaPlayer.start(); // no need to call prepare(); create() does that for you
More about: http://developer.android.com/guide/topics/media/mediaplayer.html
Intent musicIntent = new Intent();
//use Action VIEW to launch app
musicIntent.setAction(Intent.ACTION_VIEW);
String mimeType = getMimeTypeFromFile(); // in your case it is audio
Uri uri = " yourfile uri";
musicIntent.setDataAndType(uri,mimeType);
startActivity(intent);
The default view application will be opened if the mime type is changed, for video mime-type video player will be opened, for audio music player and for image gallery.
If there are multiple player then Resolver activity will be opened.
Don’t forget to catch ActivityNotFoundException
In Music player for ACTION_VIEW AudioPreview activty is called with priority. there are other activities which handle this action , just check once with action "com.android.music.PLAYBACK_VIEWER" instead of ACTION_VIEW or with it.
I want to open video file and set the previewed title in video player with a different title than the file name (which is used by default).
String videoFile = "Video file url / path";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(videoFile), "video/mp4");
// Is there an extra to set the previewed video title?
mMainActivity.startActivity(intent);
There is no documented extra for ACTION_VIEW that would offer this, and third-party video players would not have to honor it anyway. You are welcome to implement your own video player in your own app if you wish to control the title.
I call the default audio player using intent. Its playing correctly, but want to hide details of playing URL is display in top of the play.its my coding
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);
This can't be achieved with with such an implicit intent like that. This is because you have no control over the UI that is being used to play the content. In order to solve your problem, You must play the file using a specific class available in the framework.
I have app for play video in android like as
https://play.google.com/store/apps/details?id=com.vlcforandroid.vlcdirectprofree&hl=en
I want to integrate this app in my app. I have Url for video Streaming and i want to open this video in this app(Vlc Direct), Any idea?
I open this app using:
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.vlcdirect.vlcdirect");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
But how it start with video streaming, Or any other Player for video Streaming?
More like,
Intent i = new Intent(Intent.ACTION_MAIN);
i.setComponent(new ComponentName("com.vlcdirect.vlcdirect", "com.vlcdirect.vlcdirect.URLStreamerActivity"));
i.putExtra("url", url);
startActivity(i);
Which supposes that the component, activity, and payload are as shown, and also that the activity is explicitly or implicitly exported -- I don't know the actual values, or if the activity is exported. vlcdirect doesn't document this, but you can
ask the developer, or
view the log as you stream from a URL within that app, to identify the component and activity; dedex and decompile the .apk, to confirm the payload; duplicate payload classes, if necessary; give up and fume after the developer ignores you, if the activity is not exported.
Ideally you would broadcast a "view the stream from this URL" intent, and vlcdirect or any other suitable app would pick it up, but I don't know if vlcdirect or any other app respond to such.
VLC needs to be explicitly told the type:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setPackage("org.videolan.vlc.betav7neon");
i.setDataAndType(Uri.parse("http://ip:8080"), "video/h264");
startActivity(i);
i.e. just "video/*" wouldn't work for me
Previous answers didn't work me. After a bit of searching I found the official docs here.
Basically, here it is:
int vlcRequestCode = 42; //request code used when finished playing, not necessary if you only use startActivity(vlcIntent)
Uri uri = Uri.parse("file:///storage/emulated/0/Movies/KUNG FURY Official Movie.mp4"); //your file URI
Intent vlcIntent = new Intent(Intent.ACTION_VIEW);
vlcIntent.setPackage("org.videolan.vlc");
vlcIntent.setDataAndTypeAndNormalize(uri, "video/*");
vlcIntent.putExtra("title", "Kung Fury");
vlcIntent.putExtra("from_start", false);
vlcIntent.putExtra("subtitles_location", "/sdcard/Movies/Fifty-Fifty.srt"); //subtitles file
startActivityForResult(vlcIntent, vlcRequestCode);
You can remove unnecessary parts for you.
I have an application that plays video files.
I have been using code for using Videoview and starting the Videoview manually to play video files. However, I just wanted to know if I can use the default media player or video player of android rather than creating or using the VideoView to play the file..
Please make comments if the question is not clear.
Thanks alot
Sure - just use an Intent with the file Uri.
File file = new File("fileUri");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "video/*");
startActivity(intent);