I am making a video ads, now i can play video from internet, redirect to new url when user tap to the video.
But i dont know how to make Skip button, and stop , disappear my video ads after some seconds
I search google for a long time, but i cant get the solution!
can you give me some advice please?
I found the solution in this way:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
if(mVideoViewer.isPlaying()){
mVideoViewer.stopPlayback();
}
// Do something
Log.i(getCallingPackage(), "====== Auto stop ===========");
}
}, 15000);
Stop play video after 15 seconds
Try this to stop playing video.
Timer timer=new Timer();
timer.schedule(new TimerTask() {
#Override
public void run() {
if (videoView.isPlaying())
{
videoView.stopPlayback();
}
}
},10000);
Related
I'm playing a video in ExoPlayer. Now I want to distribute a specific time for that video to the user so that the user chooses.
For example, I only want to display 30 seconds to 50 seconds.
In AndroidStudio and JAVA language.
Thanks for helping me
It's not related to ExoPlayer! You can handle it on your own.
So use this snippet to solve this problem:
At the same time with starting video:
videoview.seekTo(SPECIFIED_START_TIME);
Then run this handler:
handler = new Handler();
runnable = new Runnable() {
#Override
public void run() {
if(videoview.getCurrentPosition() >= DESTINATION_TIME){ // After reaching destination time
videoview.seekTo(SPECIFIED_START_TIME);
videoview.pause(); // or stop();
}
}
};
handler.postDelayed(runnable, 0);
I'm trying to play an youtube video using Youtube Video Player in my android app from given start_time and end_time.
I used player.loadVideo("_wcs7ixyDbY", 12000), so that my video starts playing after 12 seconds. But I want to end my video at 20 seconds.
I used
player.loadVideo(videoID, 12000);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
if(player.getCurrentTimeMillis() <= 20000) {
handler.postDelayed(this, 1000);
} else {
handler.removeCallbacks(this);
player.pause();
}
}
}, 1000);
This option pause my video after 20 seconds.
How to end my video after 20 seconds (not pause)
Thank You
The Android YouTube API provides a method to stop / release the video also:
abstract void release()
Stop any loading or video playback and release any system resources used by this YouTubePlayer.
https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer
I am currently using the Glide library to show a gif in my android device, on specific event, but now I also want to set audio as background when the gif is playing, and when it stops the audio also stops!
Attempt:
Glide.with(this).load(R.drawable.somegifFile).into(imageView);
try {
if (mp.isPlaying()) {
mp.stop();
mp.release();
mp = MediaPlayer.create(context, R.raw.sound);
}
mp.start();
} catch(Exception e) { e.printStackTrace(); }
Ok try this
1. First check weather image view is null or it's not loaded with an image
2. If its loaded then it means gif starts working .. then start a timer and make it call after every 10 seconds
3. inside that's run() method refresh the audio like you did
private void startWaitingTimeRunner() {
waitingTimer = new Timer();
waitingTimer.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
// reset audio -> stop , release , play gain
}
}, 0, 10000);
}
I've been wondering if there's a way with either mp or soundpool to delay a sound and make it start exactly after 10 seconds (I have a countdown and want to add a sound effect saying 3,2,1 go! after 10 seconds.)
maybe with a handler?
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
playSound();
}
}, 10000);
I am working in an app with chronometer that when an user press the button a sound playing, and when the time at 10:00 other sound playing, but i can't play the last one, Here the code:
btIniciar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if (click){
chronometer.setBase(SystemClock.elapsedRealtime() + tempoQuandoParado);
chronometer.start();
Toast.makeText(GerenciaPartida.this, "The match begin!", Toast.LENGTH_LONG).show();
MediaPlayer musica = MediaPlayer.create(GerenciaPartida.this, R.raw.apito);
musica.start();
}
***Here i want play another sound at 10:00, when the time's over***
}
});
You can try to use timer.
Timer myTimer = new Timer();
When you start chronometer start the timer like in example below. 600000 - is 10 minutes in milliseconds.
myTimer.schedule(new TimerTask() {
#Override
public void run() {
//play sound
}
}, 600000);