Android VideoView not playing mp4 files - android

I have already seen most of the questions here but none of them helps.
Following is Streaming url it works perfectly on VLC and browser but it can't be played in android app.
Here is my code
public class VideoDemo extends Activity {
private VideoView video;
private MediaController ctlr;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.main);
/* File clip = new File(Environment.getExternalStorageDirectory(),
"90.mp4");*/
/* if (clip.exists()) {*/
video = (VideoView) findViewById(R.id.video);
//video.setVideoPath(clip.getAbsolutePath());
video.setVideoURI(Uri.parse("http://103.50.152.102:9096/LubrizolWebPrj/service/getEnqVideo/90"));
video.requestFocus();
video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
video.start();
}
});
//}
}
}

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.
Though if your format is not supported, Try using YoutubeVideoView

Related

Android video streaming from url

I use following code to play video from a url. It works fine except that It first downloads video and then plays that video
Uri uri = Uri.parse(URL);
video.setVideoURI(uri);
video.start();
But I want to stream the live video instead of downloading it and then play
I have work on YouTube Video streaming and that was without downloading video.
This will only work if you will play YouTube video .
You have to use YouTube API and using that you can easily manage your task.
You have to enable YouTube service and using Developer Key you can access YouTube API.
How to use YouTube API ? You can Find Here Sample code for same.
Out of that sample example i have use
PlayerViewDemoActivity.java & YouTubeFailureRecoveryActivity.java and that XMl view as per the needs.
Play Video
public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity
{
String youtube_id = "_UWXqFBF86U";
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.playerview_demo);
YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view); // Replace your developer key
youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
}
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer player, boolean wasRestored)
{
if (!wasRestored)
{
player.cueVideo(youtube_id);
}
}
#Override
protected YouTubePlayer.Provider getYouTubePlayerProvider()
{
return (YouTubePlayerView) findViewById(R.id.youtube_view);
}
}
Hope this will be help you,Let me know if you have any query.
There are some requirements for streaming to work.
The file might not be encoded "correctly"
http://developer.android.com/guide/appendix/media-formats.html
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.
You might be on an older version of Android that doesn't support it
HTTP progressive streaming was only added in 2.2, HTTPS only supported 3.0+, Live streaming is only supported in even later versions.
Use Like this:
Uri uri = Uri.parse(URL); //Declare your url here.
VideoView mVideoView = (VideoView)findViewById(R.id.videoview)
mVideoView.setMediaController(new MediaController(this));
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();
Another Method:
String LINK = "type_here_the_link";
VideoView mVideoView = (VideoView) findViewById(R.id.videoview);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(LINK);
mVideoView.setMediaController(mc);
mVideoView.setVideoURI(video);
mVideoView.start();
If you are getting this error Couldn't open file on client side, trying server side Error in Android. and also Refer this.
Hope this will give you some solution.
For showing buffering you have to put progressbar of ProgressDialog ,... here i post progressDialog for buffering ...
pDialog = new ProgressDialog(this);
// Set progressbar message
pDialog.setMessage("Buffering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
// Show progressbar
pDialog.show();
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(mVideoView);
Uri videoUri = Uri.parse(videoUrl);
mVideoView.setMediaController(mediacontroller);
mVideoView.setVideoURI(videoUri);
} catch (Exception e) {
e.printStackTrace();
}
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
mVideoView.start();
}
});
mVideoView.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
if (pDialog.isShowing()) {
pDialog.dismiss();
}
finish();
}
});

How to play rtsp live stream from android? (rtsp://someserver:port/live/001204A006F5.stream)

I have this video url rtsp://someserver:port/live/001204A006F5.stream and wanted to play the same from android media player. I have written following code snippet but android is showing a dialog box with the msg "Can't play this video".
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);`
videoPlayer = (VideoView) findViewById(R.id.videoPlayer);
videoPlayer.setOnPreparedListener(this);
videoPlayer.setOnCompletionListener(this);
videoPlayer.setKeepScreenOn(true);
Uri uri = Uri.parse("rtsp://someserver:port/live/001204A006F5.stream");
videoPlayer.setVideoURI(uri);
}
/** This callback will be invoked when the file is ready to play */
public void onPrepared(MediaPlayer vp) {
if(videoPlayer.canSeekForward()) videoPlayer.seekTo(videoPlayer.getDuration()/5);
videoPlayer.start();
}
Am I doing something wrong? Or it is not possible to play that link with VideoView?

Online mp4 video is not playing

what's the problem there, I have uploaded this video to server, but now its not playing, but its playing if i put this video on sdcard which is commented
public class VideoPlayerActivity extends Activity {
/** Called when the activity is first created. */
private MediaController mc;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView vd = (VideoView) findViewById(R.id.VideoView);
mc = new MediaController(this);
vd.setMediaController(mc);
Toast.makeText(this, "Video Player Started", 20).show();
//vd.setVideoPath("sdcard/video/abc.mp4");
vd.setVideoURI(Uri.parse("http://www.primesquad.com/future.mp4"));
vd.start();
}
}
streaming video differ from playing it from sdCard as you see in Android Supported Media Formats there is restrictions for streaming that don't apply when playing video.
I faced this problem with videos stream normally in HTC Desire but refuse to stream with Motorola droid

HTML5 Video Android VideoView

I am trying to play a video that is passed from a WebView in a VideoView. It works, except VideoView does not want to read it. I keep getting the error:
"Sorry, this video cannot be played."
Here is the code for the VideoView:
public class VideoHandler extends Activity {
WebView myWebView;
VideoView myVideoView;
WebChromeClient chromeClient;
WebViewClient wvClient;
Intent in;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_player);
myVideoView = (VideoView) findViewById(R.id.videoview);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(myVideoView);
String video = (MNWVMainPage.myWebView.getUrl());
myVideoView.setMediaController(mediaController);
myVideoView.setVideoPath(video);
myVideoView.start();
myVideoView.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.release();
setContentView(R.layout.mnwv_main);
}
});
}
}
Why wont this load the video?
From just reading from your code, I can see no error.
Can you check a few things:
Does the video align to the format list here?
Have you open the camera/ another VideoView? Even if you release them, the buffer seems to need some time to be actually released.

VideoView not playing on some devices

I have fragment which contains CameraPreview as background and in one of the corners i have 100x100dp video view which must play mp4 h.264 format video,
but for some reason some of the devices play other won't the problem that no error thrown it just not showing .
This is the function to prepare the video.
private void setupVideoView(){
String path = "android.resource://"+ getActivity().getPackageName()+"/"+R.raw.model_2;
Uri uri = Uri.parse(path);
mVideoView.setVideoURI(uri);
mVideoView.seekTo(1);
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
}
then after couple seconds i need to start the video, then i call
if(mVideoView != null){
mVideoView.start();
}
i had read about which codecs and format android accept and my video is perfect suit this requirements as i said above its mp4 h.264 format , any idea?

Categories

Resources