Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android intent for playing video?

I'm trying to play video's on Android, by launching an intent. 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 the HTC Hero. It seems to load a bit different video player. This does play the first video thrown at it. However, every video after that it doesn't respond. (it keeps in some loop).

If I add an explicit

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

(before the startactivity) it does work on the HTC Hero. However, since this is a HTC specific call, I can't run this code on other phones (such as the G1). On the G1, this works:

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

But this intent is missing from the hero. Does anybody know a list of intents/classnames that should be supported by all Android devices? Or a specific one to launch a video? Thanks!

like image 593
PanMan Avatar asked Oct 15 '09 12:10

PanMan


People also ask

What is the purpose of the Android Intent?

An intent is to perform an action on the screen. It is mostly used to start activity, send broadcast receiver,start services and send message between two activities.


1 Answers

Use setDataAndType on the Intent

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

Use "video/mp4" as MIME or use "video/*" if you don't know the type.

Edit: This not valid for general use. It fixes a bug in old HTC devices which required the URI in both the intent constructor and be set afterwards.

like image 197
Christian Avatar answered Sep 29 '22 09:09

Christian