Exoplayer - displaying preview when calling seekTo multiple times - android

I'm using ExoPlayer for video playback and I have a seekbar to allow user to move back or forward during playback.
What I want to achieve is for user to be able to seek while also be able to preview the frame at the current time relative to the seeker position.
Problem is, the player is displaying black frame until the user lets go of the seekbar. I'm think it's because seekTo is being called multiple times and the player just doesn't have enough time to load the frame?
Any idea how to work around this?
This is how I call the seekTo inside the seekbar listener
time_range.setOnRangeSeekbarChangeListener { minValue, maxValue ->
val mediaUri = Uri.parse(media?.dataUrl)
player?.prepare(buildClipMediaSource(mediaUri, startTime.toInt(), endTime.toInt()))
player?.seekTo((startTime * 1000f).toLong())
player?.playWhenReady = true
}

Related

Getting element which disappears after a period of time

I am trying to automate a native Android 4.2 application. The application plays a video and if you tap on the video a SeekBar widget which can be used to rewind the video is shown for 5 seconds.
The problem I am having is when I tap on the video to show the SeekBar widget it disappears too quickly before Appium can to do anything with it. e.g. get the seekbar coordinates for example.
Are there any solutions to this which don't require modifying the application itself? Is it possible to force the widget to always show for example? Or are there any other ways?
// tap to show the SeekBar widger
new TouchAction(driver).Tap(0.5, 0.5).Perform();
// get SeekBar element
IWebElement seekbar = new WebDriverWait(driver, TimeSpan.FromSeconds(60))
.Until(d => d.FindElement(By.XPath("//android.widget.SeekBar")));
// get its location.
// here is where test fails most of the time due to SeekBar widget disappearing too quickly.
var location = seekbar.Location;

Playing video in surfaceview

My app plays a video inside a surfaceview. And I stop the mediaplayer from playing when onPause(). However, when I return from another activity, the surfaceview is all black and starts to show frames only if I start playing video again. I want to know if there is a method to preserve the last frame when it stops. Thanks a lot.
I used 2 SurfaceViews, first for playing videos and second surf for displaying pictures.
when I return from pause, if mediaplayer is not playing, I get current frame of video by this part of code:
try {
mediaMDRetriever.setDataSource(mediaPath);
picBitmap = mediaMDRetriever.getFrameAtTime();
} catch (Exception e) {
}
and draw it on the second surfview.
you can clear second SurfaceView if needed by the following code:
Canvas surfCanvas = surfHolder2.lockCanvas();
surfCanvas.drawColor( 0, PorterDuff.Mode.CLEAR );
surfHolder2.unlockCanvasAndPost( surfCanvas );

Adding markers at intervals to videoview player in android

Is it possible to add markers to video's at regular intervals on the video view progress bar so that the video can stop at that point and start another activity? For instance at 10 min into a video I need a marker in the videoview progress bar, and when the video comes to 10 min, the video stops and the other activity starts ?
Yes, It possible, (Rough Idea..)
The exact method I don't know, but you can make a Hack.. By using methods
public int getDuration() and getCurrentPosition() of
MedaiPlayer class.
Basic Idea, What to do is make a ProgressBar (for complete video duration) and now when you add marker to it just get the duration of that marker (using some mathematical formula). And now check for current Position of your Video file, If its your marker position then using condition stop your video ans start a new Activity..
(If I'm going wrong let me know)

AndEngine - lagging when playing sound

I'm creating a simple game with AndEngine. A ball is dropped toward a floor, and whenever it collides with the floor, I want to play a short colliding sound. In method onUpdate(), I check for collision and play sound accordingly.
I use class Sound for playing sound (as in the SoundExample of AndEngine). Testing on Samsung Galaxy S2.
The problem is the program gets lagged when the sound is played. And it even affects game physics (sometimes the ball bounces higher than the highest point when disabling sound).
This is the code:
public void onUpdate(float pSecondsElapsed) {
// mSound.play();
if (this.mSprite.collidesWith(ball.getSprite())) {
if (!colliding && mSound != null){ // play sound for first collision only
mSound.play();
colliding = true;
}
}
else{
colliding = false;
}
}
If I remove mSound.play() or keep playing sound (remove comment at line 2), the program works smoothly.
Does anyone encounter the same problem? And have a solution to get rid of the lag? Many thanks!
as that you mentioned that it works smoothly when you keep playing the sound .. then the problem is not with the sound
the collidesWith() method is probably your culprit, remember that onUpdate gets called every frame .. maybe you'll have to redesign your code or limit the number of frames per second [change your engine options to use a FixedStepEngine to achieve that]

VideoView and step play (frame by frame)

I would like to play frame by frame with the videoview.
I have this:
mVideoView.seekTo(mVideoView.getCurrentPosition()+1);
But after this I do not see the frame until I click play... I do not want that, I just want to see the next frame.
Also - can I do the same for previous frame?
Thanks in advance.
It will not seek while paused. But you can always pause right after seeking, if you use a SurfaceView and a MediaPlayer because VideoView doesn't have the onSeekComplete callback.
public void seek() {
mediaplayer.start();
mediaplayer.seekTo(mediaplayer.getCurrentPosition()+1);
}
public void onSeekComplete(MediaPlayer mp) {
mediaplayer.pause();
}
This will seek and display something. Unfortunately you will find that this does not allow you to play frame by frame.
You can use MediaMetadataRetriever to select the frame you want and next get it as a BitMap using MediaMetadataRetriever.getFrameAtTime(long timeUs). It will work much better than using a MediaPlayer.
I hope it is useful.

Categories

Resources