Adding markers at intervals to videoview player in android - 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)

Related

Exoplayer - displaying preview when calling seekTo multiple times

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
}

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;

How to resume and pause ObjectAnimator in Android for API Levels below 19?

I am aware that API level 19 supports pause() and resume() on ObjectAnimators. But in my project at API level 14, I have an ObjectAnimator which is applied to an Image view to rotate it. I want to pause the animation provided by the ObjectAnimator on touch and resume it from the place where the image view was (before touch down).
So I attempted to save the current play time and cancel the object animator on my stopAnimation() function.
private void stopAnimation(){
currentTime = mGlobeAnimator.getCurrentPlayTime();
mGlobeAnimator.cancel();
}
In the startAnimation() function, I recreate the animator, set its target to the image view, set the saved play time and start it.
private void startAnimation(Context context, View view, float startAngle) {
ObjectAnimator globeAnimatorClone = (ObjectAnimator)AnimatorInflater.loadAnimator(context, R.animator.rotate_globe);
globeAnimatorClone.setTarget(mImageView);
globeAnimatorClone.setCurrentPlayTime(currentTime);
globeAnimatorClone.start();
}
This does not work. Would anybody help please with any pointers to pause and resume animation provided by animator for API level before 19?
I think I got it working by starting the animator and then setting the currentPlayTime(). The documentation clearly tells (which I just stumbled upon) that if the animation has not been started, the currentPlayTime set using this method will not advance the forward!
Sets the position of the animation to the specified point in time. This time should be between 0 and the total duration of the animation, including any repetition. If the animation has not yet been started, then it will not advance forward after it is set to this time; it will simply set the time to this value and perform any appropriate actions based on that time. If the animation is already running, then setCurrentPlayTime() will set the current playing time to this value and continue playing from that point. http://developer.android.com/reference/android/animation/ValueAnimator.html#setCurrentPlayTime(long)
private void stopAnimation(){
mCurrentPlayTime = mRotateAntiClockwiseAnimator.getCurrentPlayTime();
mRotateAntiClockwiseAnimator.cancel();
}
private void startAnimation() {
mRotateAntiClockwiseAnimator.start();
mRotateAntiClockwiseAnimator.setCurrentPlayTime(mCurrentPlayTime);
}
What you are doing is that it will just restart your animation, instead you can create a custom class for animation with pause and resume method.
You need to first check if the device is 19 api and above if it is then use the native pauses and resume of the object animator else use the regular Animation designed from api 1, you can follow this thread for pause and resume below api 19.
Its probably too late for me to answer, i just came across this problem and i solved it using your method.
i just added two things to your approach
1. In the start of animation check if the ** mCurrentPlayTime** is greater than zero.if its >0 then setCurrentPlayTime. otherwise its useless.
2. when your animation ends make it zero again.

How to stop objects moving on the same path in Corona sdk

I have player and enemy objects on the scene. The enemies are generated randomly at the specified path, and the other one is player which is generated from the opposite side of enemy. I want to stop both these objects if they come some distance apart on the same path, and if any one of the two objects are destroyed by the firing then the other remaining object whether it must be enemy or player must start moving.
I have implemented below code, and it is working for the first time when they both are in front of each other and 200 distance apart. Suppose player fire the enemy then the enemy gets destroyed, and player starts moving but if now another enemy comes in front of the player then player does not stop, it keeps on moving, but the enemy stops. Please suggest some solution. Thanks...
for j=#enemy, 1, -1 do
if(enemy[j].y~=nil and player.y~=nil then
diff=player.y-enemy[j].y
if(enemy[j].x==player.x) then
if(diff<=200) then
enemy[j].Speed=0
player.speed=0
end
end
else
player.speed=-50
enemy[j].Speed=2
end
end
You are setting player.speed=-50 for any nil enemy[j].y
Perhaps you should move the line
player.speed=-50
to above the for loop. That way, the player will move by default, but can be stopped by any enemy.

my line of code is not executing in delay - android

The strangest thing is happening. In my onClick(View ...) I have blocks of code, mostly 'if/else' blocks. The sequence is (in pseudo-code, to save you lengthy code):
I have an image that needs setting using imageButton.setImageResource(randomImage); then
I have a MediaPlayer associated with this image that needs playing, then
I place a sleep(1800) here otherwise the MediaPlayer runs into the next MediaPlayer (this works fine)
This image is compare to another image. If its not the same, then another MediaPlayer named 'boo' is played, and the image that should have been displayed in code 1. above, is replaced by 'flag' image. else //if its the right image then
Switch to 'another' image, play it's corresponding MeidaPlayer, Play a 'cheers' MediaPlayer and change image to a 'tick' image, then do some other logic stuff.
But what is happening is that the code 2. is playing, code 3. is happening. code 4. only the 'boo' mediaplayer is happening and I notice the imagebutton flashing. The image that was supposed to be set in code 1. is delayed and is happening only AFTER the 'boo' mediaplayer. The 'flag' image that replaces the first image setting in code 1. is happening but because code 1. is in delay, what is happening is that the image is not changing (although it is, it's just in delay and then it flashes so quickly that it appears not to change). So code 1. is in delay.
Also, if it goes into the else and the right image is clicked, then the image in code 5. DOES switch to 'another', but the corresponding MeidaPlayer doesn't play, the 'cheers' MediaPlayer doesn't play, the 'tick' image doesn't display, and the other logic doesn't occur. Its as if it is ignoring the code.
What's happening here? Is this a multi-threading situation here? Grouping different parts of the code in their own threads and starting them at once only throws exceptions. Any help will be greatly appreciated!
If you want to delay your code, use Handler.postDelayed(Runnable, long). This won't block the UI thread, and will execute when you want it to.
Whitout your code, it's really unclear what are you trying to achive, and how are you trying to achieve it.
Just to explain Adam's idea.
Put this in your Activity class :
final Handler handler = new Handler();
Runnable _rnbl = new Runnable() {
public void run() {
// Your code
}
};
And call it like this
handler.postDelayed(_rnbl , 5000);

Categories

Resources