Android Video Streaming playing slowly? - android

I am developing a video based android application. I want to play a video (Video Format: mp4) from a URL. But it's not live stream video stored in the server. Get video URL from JSON object and playing video. The video is playing but not in a good manner.
Sometimes the audio is mismatched then take more time to play some take more time to buffer. But with the same video and same wifi speed I have on my system when playing with chrome it's playing well. I don't know what I am doing wrong? I also tried with android video view but the same problems occurred.
My code to start video player
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(uri), "video/*");
startActivity(intent);
My code to playing with video view
VideoView vidView = (VideoView)findViewById(R.id.myVideo);
String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.start();

What android version did you try? Because https is not supported before android 3.1.
Check supported protocols and media formats here

You can use the MediaPlayer to do this.
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Map<String, String> headers = new HashMap<String, String>();
headers.put("rtsp_transport", "tcp");
headers.put("max_analyze_duration", "500");
mMediaPlayer.setDataSource(context, Uri.parse(videoUrl), headers);

Related

how does android.net.Uri work

now I'm developing an android Video on Demand or Audio on Demand Player, I notice there's a function in package android.net.Uri, part of my code of play the video or audio is like this:
Play Audio part:
mPlayer = new MediaPlayer();
mPlayer = MediaPlayer.create(this, Uri.parse("http://.../MJ.mp3"));
mPlayer.setLooping(true);
mPlayer.start();
Play Video Part:
VideoView vidView = (VideoView)findViewById(R.id.myVideo);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
String vidAddress = "https://.../ABC.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
vidView.start();
I'm wondering does this satisfy the video or audio on demand request? In an other word, when I play the audio or video using the URI function, does it work like Youtube, which downloads just part of the video and plays the video, or download the whole file first then play it?

how to play and upload RTSP protocol through Live Video Stream on Android

Hello i have one rtsp live video url, I have't know how to play this live stream live Video url.
i am working on android sample application. Please share your guide with me.
Following code using to play live streaming url.
Don't have any idea, how to get live video streaming. Please suggest me any idea to send to live video stream to server.
below are my sample code.
public class MultimediaActivity extends Activity {
private static final String rtspURL = "rtsp://URL_IP:PORT+video+FileName";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.video);
Log.v("Video", "***Video to Play:: " + RTSP);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
Uri video = Uri.parse(rtspURL);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
}
}
please suggest me, What should i do..?
Thank you..
Use this code for playing on player
Intent i1 = new Intent (Intent.ACTION_VIEW ,Uri.parse(rtspURL));
startActivity(i1);
and use this code for videoview
VideoView v1 = (VideoView)findViewById(R.id.videoView1);
v1.setVideoPath(rtspURL); //your rtspurl
v1.start()
this work for me ...

Android MediaControler does not work with video from url

I have video player, video is from url. It works- I can start and stop playing video. I would like to have a possibility to move progres in MediaController. I have set the MediaController, but it doesn't work. When I use a video from file i can seek/move the video progress, but with the video from url it doesn't work.
There is my code:
videoFrame = (FrameLayout) findViewById(R.id.videoField);
mediaController = new MediaController(VideoPage.this);
videoPlayer = new VideoView(context);
videoFrame.addView(videoPlayer);
videoPlayer.setVideoURI(Uri.parse(url));
mediaController.setMediaPlayer(videoPlayer);
videoPlayer.setMediaController(mediaController);
videoPlayer.requestFocus();
videoPlayer.start();
You have to check if you can seek forward:
if(videoPlayer.canSeekForward()){
...
}
and this is just possible, when you get a duration for the videostream, but some streams don't have a duration, for example if you stream tv content or a live stream.
int duration = videoPlayer.getDuration()

How to play a mp4 videos in Android through Server

I am using following code to play mp4 videos which is stored in sever.... And i am get error like this->
This Video can not be played????
Uri video = Uri.parse("http://129.0.0.....");
MediaController mediaController = null;
mVideoView.setMediaController(mediaController);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://129.0.0....")));
mVideoView.setVideoURI(video);
mVideoView.setVideoPath("http://129.0.0......");
mVideoView.requestFocus();
mVideoView.start();
This might be helpful to you i have used this in android 2.3.3.
public void videoPlayer(String path, String fileName, boolean autoplay){
//get current window information, and set format, set it up differently, if you need some special effects
getWindow().setFormat(PixelFormat.TRANSLUCENT);
//the VideoView will hold the video
VideoView videoHolder = new VideoView(this);
//MediaController is the ui control howering above the video (just like in the default youtube player).
videoHolder.setMediaController(new MediaController(this));
//assing a video file to the video holder
videoHolder.setVideoURI(Uri.parse(YOUR_SERVER_VIDEOFILE_URL));
//get focus, before playing the video.
videoHolder.requestFocus();
if(autoplay){
videoHolder.start();
}
}
Always pass the mp4,3gp etc video format link in URI.Try this code:
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("http://hermes.sprc.samsung.pl/widget/tmp/testh.3gp"));
videoView.requestFocus();
videoView.start();

Play mp4 Video using <Embed> tag on Android Webview

I want to play mp4 video using tag on Webview. I have few constraints for not to use HTML5 tag. I have looked code to play YouTube video on webview. But YouTube uses .flv format. I have .mp4 video to play.
Thanks in advance.
You could play the video directly, without a WebView:
VideoView videoView = new VideoView(this);
setContentView(videoView);
Bundle extra = getIntent().getExtras();
if (null != extra && extra.containsKey("url")) {
String url = extra.getString("url");
Uri uri = Uri.parse(url);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(uri);
videoView.start();
}

Categories

Resources