When trying to play a Video on Android, the app is prompting the user to select the player.
In code, I am doing the following. Is it possible that I select the player so the user wont' be prompted?
String url = (String) v.getTag();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "video/*");
startActivity(intent);
Below is the image this is shown to the user:
Edit pasted as answer
intent.setPackage("com.sec.android.app.videoplayer");
I take it back. That might cause a problem on some phones. It worked on S4. However,It might not work on others. More work needs to be done.
Related
I am having a weird problem. (I am new to android) In my app I have an intent to launch the video camera as well as one to launch the camera. Now what seems to happen is when I click on the image button to display image, it then display the images. But when trying to display video it says "unable to play video". So I thought there was something wrong with my phone so I restarted my phone and it then seemed to play. So when testing again it doesn't.
So I know there is nothing wrong with my code, but can't seem to display the video after it has been taken. (and only plays after a reboot of the device)
Could someone please help me?
Thanks
EDIT
To take the video I use:
Intent imageIntent = new Intent (android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
timeStamp = new SimpleDateFormat("ddMMMyyyy_HH:mm:ss").format(new Date());
File videosFolder = new File(Environment.getExternalStorageDirectory(), "Cool Videos");
videosFolder.mkdirs();
image = new File(imagesFolder.getPath(), "Cvidoes_" + timeStamp + ".mp4");
fUri = Uri.fromFile(image);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(imageIntent, TAKE_PICTURE);
And then in my "display full screen"
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(temp_file),getMimeType(temp_file.getAbsolutePath()));
startActivity(intent);
But the weird thing is worked before I recently updated to android version 5.0.
EDIT 2
Okay I have solved the issue.
I have pretty much nothing in my "OnActivityResult" section, but added this and all is working again:
MediaScannerConnection.scanFile(
getApplicationContext(),
new String[]{image.getAbsolutePath()},
null,
new OnScanCompletedListener() {
#Override
public void onScanCompleted(String path, Uri uri) {
Log.v("VideoScan",
"file " + path + " was scanned seccessfully: " + uri);
}
});
So why since the update it stopped working and now have to add this?
So why since the update it stopped working and now have to add this?
Strictly speaking, we can't really answer this definitively.
What you added was code to arrange to have your video be indexed by the MediaStore. A video player receiving a file:/// Uri — as you are using in your ACTION_VIEW Intent — should not really care about MediaStore. Apparently, yours does, or does after your device was upgraded to Android 5.0. IMHO, that's a bug in the video player.
Now, in general, if you want the user to be able to work with the video separately from your app, you need to get it indexed by the MediaStore. That will happen automatically... eventually. Your code addition makes it happen much more quickly, which is generally a good idea.
So, I'd look at it more that you tripped over a bug in the video player, whose fix happened to be some code that you probably needed anyway.
In other words, it's just another day at the office... :-)
I'm trying to play a known playlist in the Spotify app. The best I've got is to load the playlist, but not play it.
Two things I've tried. Firstly to play from search:
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setComponent(new ComponentName("com.spotify.music",
"com.spotify.music.MainActivity"));
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS,
MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE);
intent.putExtra(MediaStore.EXTRA_MEDIA_PLAYLIST, <PLAYLIST>);
intent.putExtra(SearchManager.QUERY, <PLAYLIST>);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I've tried replacing PLAYLIST with the name of a known playlist. Also tried things like "4Rj0zQ0Ux47upeqVSIuBx9", "spotify:user:11158272501:playlist:4Rj0zQ0Ux47upeqVSIuBx9" etc. All these do is a failed search for these strings.
Second attempt is the View intent:
String uri = "https://play.spotify.com/user/11158272501/playlist/4Rj0zQ0Ux47upeqVSIuBx9";
Intent intent= new Intent( Intent.ACTION_VIEW, Uri.parse(uri) );
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
This loads the playlist, but does not play. If I then use one of the many ways to send a KEYCODE_MEDIA_PLAY key, it just resumes the currently playing list, not this newly loaded list.
Any help from anyone (including Spotify devs)?
BTW I don't want to use the Spotify SDK to implement my own Spotify Player - it seems a shame to have to do this when a perfectly good player is already installed on a user's device.
I found the answer from this blog. What I was missing was the playlist URI as a data Uri in the intent. So not using the proper Android way of Play from search.
So, using the first method from the question, you end up with this:
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setData(Uri.parse(
"spotify:user:11158272501:playlist:4Rj0zQ0Ux47upeqVSIuBx9"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
3 things to note:
the Uri can't be the https://play.spotify... but has to be the colon seperated type.
the Spotify account must be premium, otherwise the playlist opens but does not play.
this does not work if the screen is off, or lock screen is showing. The spotify activity needs to display on the screen before it loads and plays!
This final point means it isn't actually usable for me... so not accepting answer yet.
Just add :play to Spotify Intent URI
spotify:album:3avifwTCXoRzRxxGM1O0eN:play
hey every one I wonder how can I open specific post, album or video from android app in facebook app, I used this code to open specific post but it doesn't work
mActivity.getPackageManager().getPackageInfo("com.facebook.katana", 0);
String uri = "fb://post/" + mData.get(position).getmPostID();
Intent viewIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(uri));
I want to open this post
https://www.facebook.com/Y.Anti.coup.D/posts/707105232705409
Sorry for my bad English and I hope that you understand my problem
In the app I am working on I want to support Netfilx streaming. I intend on doing this by simply starting Netflix and passing a specific URI so it plays a specific video when started. Simple right? Well, the issue is I'm not sure how to pass the video id info in the Intent I use to start the Activity.
I've read the post here , but am unsure where to use this. I used Intent.setData() since it accepts a URI, but to no avail.
Here is what I have been doing (I am hard coding the movie data, this is just for testing purposes) :
// the Netflix intent
Intent intent = getPackageManager().getLaunchIntentForPackage("com.netflix.mediaclient");
//the uri
Uri uri = Uri.parse("http://movies.netflix.com/WiPlayer?movieid=70266228&trkid=13462049&ctx=0%2C1%2Ce2bd7b74-6743-4d5e-864f-1cc2568ba0da-61921755");
intent.setData(uri);
//launches but does not go to the video
startActivity(intent);
I've also tried using the URI protocol in the link above like so:
Uri uri = Uri.parse("nflx://movies.netflix.com/WiPlayer?movieid=70266228&trkid=13462049&ctx=0%2C1%2Ce2bd7b74-6743-4d5e-864f-1cc2568ba0da-61921755");
but still am not seeing the video play.
I feel like I am missing something simple here, although I have had very little luck Googling for this, I could find next to nothing about starting the Netflix Android app from another application. The Netflix developer resources don't have any info on this.
Does anyone have any suggestions on how I can do this or where I should be looking for documentation on this? Any help would be appreciated. Thanks much!
Just some Android Apps intent names to help anyone.
Format: appName, packageName, className
Skype: com.skype.raider, com.skype.raider.Main
Netflix: com.netflix.mediaclient, com.netflix.mediaclient.ui.launch.UIWebViewActivity
ESexplorer: com.estrongs.android.pop, com.estrongs.android.pop.view.FileExplorerActivity
Youtube: com.google.android.youtube,com.google.android.youtube.HomeActivity
Chrome: com.android.chrome,com.google.android.apps.chrome.Main
VLC: org.videolan.vlc, org.videolan.vlc.gui.MainActivity
MBOXSettings: com.mbx.settingsmbox, com.mbx.settingsmbox.SettingsMboxActivity
I've managed to do this. With the following code. First you need the movieId (or videoId) for netflix, then compose the URL to watch.
String netFlixId = "43598743"; // <== isn't a real movie id
String watchUrl = "http://www.netflix.com/watch/"+netFlixId;
Then with this intent
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.netflix.mediaclient", "com.netflix.mediaclient.ui.launch.UIWebViewActivity");
intent.setData(Uri.parse(watchUrl));
startActivity(intent);
}
catch(Exception e)
{
// netflix app isn't installed, send to website.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(item.url));
startActivity(intent);
}
I haven't tried with TV Shows yet. But this works beautifully. If you want to send to the profile page of the movie.. Send it to a url formatted this way
http://www.netflix.com/title/324982
I also found out how to search for a title.
try {
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setClassName("com.netflix.mediaclient", "com.netflix.mediaclient.ui.search.SearchActivity");
intent.putExtra("query", item.label);
startActivity(intent);
}
catch(Exception e)
{
Toast.makeText(this, "Please install the NetFlix App!", Toast.LENGTH_SHORT).show();
}
Here is how to start a movie from an ADB command for com.netflix.mediaclient
adb shell am start -n com.netflix.mediaclient/.ui.launch.UIWebViewActivity -a android.intent.action.VIEW -d http://www.netflix.com/watch/60000724
I still can't find a way to do it for com.netflix.ninja (Netflix for Android TV)
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.