Raheel Khan Lodhi
Raheel Khan Lodhi

Reputation: 13

Can't Play Video using android default video player using intent

My Android Device can play directly the same Video MP4 and AVI Video Files but while using source code, it is giving me an error "Can't Play this Video" after a progress dialog box with message of "Loading Video".. I am using both the ways: 1. First Method:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse("http://localhost/h.mp4");
                    intent.setDataAndType(data, "video/*");
                    startActivity(intent);
  1. Second Method:

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    

ANY HELP ?

Upvotes: 0

Views: 3162

Answers (2)

sealz
sealz

Reputation: 5408

You can try VideoView. (Documentation)

try{
      VideoView videoView = (VideoView) findViewById(R.id.VideoView);         
      MediaController mediaController = new MediaController(this);
      mediaController.setAnchorView(videoView);
      // Set Audio/Video
      String strfilename = "http://localhost/h.mp4";
      Uri video = Uri.parse(strfilename);
      videoView.setMediaController(mediaController);
      videoView.setVideoURI(video);
      videoView.start();   
} 
catch (Exception e) {
//Handle Errors
} 

EDIT
Android is also picky about the way videos are encoded when using videoView. (See below quote from link)

For video content that is streamed over HTTP or RTSP, there are additional requirements:

•For 3GPP and MPEG-4 containers, the moov atom must precede any mdat atoms, but must succeed the ftyp atom.
•For 3GPP, MPEG-4, and WebM containers, audio and video samples corresponding to the same time offset may be no more than 500 KB apart. To minimize this audio/video drift, consider interleaving audio and video in smaller chunk sizes.

Upvotes: 1

Squeezle
Squeezle

Reputation: 1

In your AndroidManifest.xml don't forget to also add -

<uses-permission android:name="android.permission.INTERNET"/>

so that it can access the http.

Upvotes: 0

Related Questions