Android intends to play video?

I am trying to play a video on Android by running intention. The code I'm using is:

tostart = new Intent(Intent.ACTION_VIEW); tostart.setDataAndType(Uri.parse(movieurl), "video/*"); startActivity(tostart); 

This works on most phones, but not on HTC Hero . It seems to be loading a slightly different video player. This is truly the first video thrown at him. However, each video after that does not respond. (he keeps in some cycle).

If I add explicit

 tostart.setClassName("com.htc.album","com.htc.album.ViewVideo"); 

(before work) it works on HTC Hero . However, since this is a special HTC call, I cannot run this code on other phones (for example, G1 ). On G1, this works:

 tostart.setClassName("com.android.camera","com.android.camera.MovieView"); //g1 version 

But this intention is absent from the hero. Does anyone know a list of intentions / cool names that should be supported by all Android devices? Or specific to launch the video? Thank!

+46
android android-intent sdk video
Oct. 15 '09 at 12:39
source share
4 answers

Use setDataAndType in intent

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(newVideoPath)); intent.setDataAndType(Uri.parse(newVideoPath), "video/mp4"); startActivity(intent); 

Use "video / mp4" as a MIME or use "video / *" if you do not know the type.

+65
Jan 07 '13 at
source share

I came across this with a Hero using what I thought was a published API. In the end, I used the test to find out if I could get the intent:

 private boolean isCallable(Intent intent) { List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; } 

When using, when usually I start my activity:

 final Intent intent = new Intent("com.android.camera.action.CROP"); intent.setClassName("com.android.camera", "com.android.camera.CropImage"); if (isCallable(intent)) { // call the intent as you intended. } else { // make alternative arrangements. } 

Obviously: if you go down this route - using non-public APIs, you must absolutely provide a reserve, which, as you know, definitely works. It doesn't have to be perfect, it could be a toast saying that it is not supported for this phone / device, but you should avoid an uncaught exception. obviously.




I find the Open Intents Registry of Intents Protocols quite useful, but I have not found the equivalent of a list of TCK types that absolutely must be supported, and examples of which applications use different tubes.

+11
Oct 23 '09 at 16:22
source share

The following code works fine for me.

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieurl)); startActivity(intent); 
+11
Nov 16 2018-11-11T00:
source share

from the debugging information, it seems that the VideoIntent from MainActivity cannot send the video path to VideoActivity . It gives a NullPointerException error from uriString . I think some of this code is from VideoActivity :

 Intent myIntent = getIntent(); String uri = myIntent.getStringExtra("uri"); Bundle b = myIntent.getExtras(); startVideo(b.getString(uri)); 

Can't get uri from here:

 public void playsquirrelmp4(View v) { Intent VideoIntent = (new Intent(this, VideoActivity.class)); VideoIntent.putExtra("android.resource://" + getPackageName() + "/"+ R.raw.squirrel, uri); startActivity(VideoIntent); } 
+1
Apr 15 '13 at 16:40
source share



All Articles