Question

I am new to android.

I have created a simple example for playing video files with the videoView. the xml part contains only one Button and a VideoView, Here is the code for ButtonClick

@Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            Uri uri = Uri.parse("http://www.learnixmba.com/doajax.php?profile=2809");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.setDataAndType(uri, "video/*");
            startActivity(intent);

        }

when I try running this app on Emulator I am getting error message as "Cant Play Video" Why I am getting this message and the logcat shows one error as

12-30 05:25:37.623: E/cutils-trace(1370): Error opening trace file: No such file or directory (2)

need answers and advises Thanks in advance

edit:

I tried loading this same video url to a webView., and it shows...,

"some of your technology may be out of date this video may not play properly"

what is the problem ? am I using outdated tools??

Was it helpful?

Solution

You have to provide a direct link to your video.

Try to change this line:

 Uri uri = Uri.parse("http://www.learnixmba.com/doajax.php?profile=2809");

To this:

 Uri uri = Uri.parse("http://pdl.vimeocdn.com/01593/020/145269025.mp4?token2=1388403392_f17d62baae773f48f5b1565a69857345&aksessionid=1ba8f3ac4cafca62");

EDIT: DISPLAY YOUTUBE VIDEOS

String videoId = "0HDsz3C9IHg"; // id of the youtube video you want to display
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"+videoId)); 
intent.putExtra("VIDEO_ID", videoId); 
startActivity(intent); 

OR DIRECT LINK TO VIDEO, PLAYING IN THE YOUTUBE PLAYER:

Intent videoClient = new Intent(Intent.ACTION_VIEW);
videoClient.setData("VALID YOUTUBE LINK WITH HTTP");
videoClient.setClassName("com.google.android.youtube","com.google.android.youtube.WatchActivity");
startActivity(videoClient);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top