I'm using YouTubePlayer to play YouTube video and use cueVideo(videoId) to load video, Which is working fine if video not contain Ad but video contain Ad then cueVideo(videoId) will not load video.
Also seen some discussion regards such problem which are suggested use loadVideo(videoId) instead of cueVideo(videoId) but as per my requirement i shown image until video not buffer and when video buffered hide image and show YouTubePlayer, So have to use cueVideo(videoId) instead of loadVideo(videoId).
Does any one having such issue ? thanks in advance for any suggestion or help.
Below is my code to load video :
youTubePlayer.cueVideo(videoId);
Preface: YouTube does not allow any View to be displayed over its video player.
My guess is that your "loading image", since it is displayed over the video player, is covering the ad that starts rolling for some videos. You can check this by reading the logs and keeping an eye for a warning thrown by the YouTube SDK.
I would suggest to use the YouTubePlayer.PlayerStateChangeListener callback, that offers the following methods:
abstract void onAdStarted()
abstract void onVideoStarted()
abstract void onLoaded(String videoId)
By using these methods, you can guarantee that your "loading image" is properly hidden just before the video or the ads starts playing.
Related
I'm currently using videoView in recyclerView to load the video from url.
My onBindViewHolder:
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
Uri uri=Uri.parse(arrayList.get(position).getUrl());
holder.videoView.setVideoURI(uri);
MediaController mediaController=new MediaController(context);
mediaController.setAnchorView(holder.videoView);
holder.videoView.setMediaController(mediaController);
holder.videoView.setOnClickListener(v -> holder.videoView.start());
}
I observed that when I scroll up the first video stops and and second video start playing, if I'm again trying to play the first video that loads again.
My Question :
1. I saw many tutorials they are saying to add 3-4 extra class to cache the video using exoplayer. Can we cache video by writing 5-6 lines of code?
2. If user scrolls the recyclerView before complete loading of video, how will it behave will it cache the half loaded video?
I want to achieve autopaly like youtube feed. If you can please help me.
I play a video in a videoview from an URL...everything works fine and even the video plays
But the only problem is that the video takes almost 10 seconds to start playing which might be kind of annoying to the user
I have tried different URLs and its the same, the videos are 360p and 6sec long
Is it the default media player that is slow?
I have the stack overflow but could not find a suitable answer and ever searched for various 3 rd party videos libraries but could not find one
Even tried google's exoplayer library but the documentation is not that good in my view
Is there any solution how to overcome this problem?
my code
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String videeourl = "http://techslides.com/demos/sample-videos/small.3gp";
VideoView videoView = (FastVideoView)findViewById(R.id.video);
videoView.setMediaController(new MediaController(this));
videoView.setVideoPath(videeourl);
videoView.start();
}
}
Consider using Exoplayer. You can find the open source project here:
https://github.com/google/ExoPlayer
It uses Dynamic Adaptive Streaming over HTTP (DASH),breaks long content into HTTP segments.
You can follow this tutorial step-by-step to integrate ExoPlayer (ExoPlayer is the video player running in the Android YouTube app.) to your app, it's not that complicated as you thought.
https://codelabs.developers.google.com/codelabs/exoplayer-intro/index.html#0
By the way, there are a lot of good assignments in Google CodeLabs, you should check it out.
I have a link in the form
http://something.com/some/play.php
When I simply put and go on the browser, the video gets played. It is a live video.
I want to make request to this URL and then run the video in android view.
How to achieve that?
With a VideoView, you should be able to do the following:
String path="http://something.com/some/play.php";
Uri uri=Uri.parse(path);
VideoView video=(VideoView)findViewById(R.id.VideoView01);
video.setVideoURI(uri);
video.start();
Check out the documentation regarding VideoView, and here's an example on how you can stream using VideoView.
Trying to get a simple video clip playing in a loop. I got the video to play just fine. However, there are two problems I'm having.
If the user clicks the Home button, effectively hiding the app. Then they go back to it, the video is gone and doesn't reload.
Everything as far as initializing the video only takes place in the typical onCreate for the view that holds it. Where should I be calling the video from to start it to ensure that it always actually starts?
I can only get the device to find the video when pulling it from the web. I see in the logs that when I try to reference the clip from the RAW folder, it cannot find it.
VideoView myVideoView = (VideoView)findViewById(R.id.lighterView);
myVideoView.setVideoURI(Uri.parse("android.resource://com.android.AndroidVideoPlayer/"+R.raw.[videoclip]));
myVideoView.requestFocus();
myVideoView.start();
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer myVideoView) {
myVideoView.setLooping(true);
}
});
The above chunk of code works fine if I use a URL to my website. But locally, it cannot find the clip.
Instead of just load/play video in onStart() method I suggest you to look at some well written code about VideoView, because the best way to connect your video to your interface is manage your VideoView(that implements surfaceView) callBack.
You can find a good example at the following link;)
http://alvinalexander.com/java/jwarehouse/android/core/java/android/widget/VideoView.java.shtml
I am developing one android application in which I am able to play all the videos and Images in SD card.But I am getting the blank screen for 2 or 3 seconds while displaying video after image. I don't want that blank screen, I need to show the video immediately after image. Can anyone tell how to do that?
Try playing video inside onPrepared(), first of all just initialize the VideoView with its path or URI of the video and then play it,
mVideoView.setVideoURI(Uri.parse(path));
mVideoView.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mVideoView.start();
}
});
This seems to happen when you're loading image and video and try to navigate away from image to video before the image.This problem occur when image size and video size is large.so check image and video size.otherwise give permission in android manifest
android:largeHeap="true"