user1425825
user1425825

Reputation: 15

How to play an mp4 video from server in android?

I am able to display a 3gp video from server. But when I tried to play an mp4 video it displayed an alert saying that Sorry,this video cannot be played. Please help me in this regard.

package com.play.video;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class PlayvideofromserverActivity extends Activity
{
    private VideoView vView;
    private String vSource;


    @Override
    public void onCreate(Bundle savedInstanceState) 
    { 

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);


        vView = (VideoView)findViewById(R.id.vview);


        vView.requestFocus();


            vSource ="http://server.com/testvideo.mp4";
            vView.setVideoURI(Uri.parse(vSource));


        vView.setMediaController(new MediaController(this));


        vView.start();
    }
} 

Upvotes: 1

Views: 4272

Answers (3)

Zar E Ahmer
Zar E Ahmer

Reputation: 34360

Android doesn't always play mp4.

MP4 is just a container - the video and audio stream inside it will both be encoded in different formats.

Android natively only supports certain types of formats. There is a list here:

http://developer.android.com/guide/appendix/media-formats.html

Make sure the video and audio encoding type is supported. Just because it says "mp4" doesn't automatically mean it should be playable.

Credit goes to Ken Wolf

Upvotes: 1

mohamed
mohamed

Reputation: 303

Try this code

MediaController mc = new MediaController(this);
videoView.setMediaController(mc);

String s=Common.videofilepath;
//Set the path of Video or URI
videoView.setVideoURI(Uri.parse(Common.videofilepath));

//Set the focus
videoView.requestFocus();
videoView.start();

Upvotes: 0

Md Abdul Gafur
Md Abdul Gafur

Reputation: 6201

Try this code. It help you.

myVideoView.setMediaController(new MediaController(this));
myVideoView.setVideoPath(videoSource);
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
  public void onPrepared(MediaPlayer mp) {
    myVideoView.start();
  }
});

Thanks

Upvotes: 2

Related Questions