Controlling video playback speed during online video streaming in android - android

I am to play video in android from Vimeo doing online streaming. For this, Right now, I am using VideoView. Now, I wanna control the video playback speed control feature like: 0.5x,1x,1,5x,2x And video cache support.
Are both of these possible with Android VideoView or is there any third player that I can use?
Help!

Hi for the best control i advice you with vlc lib or pvPlayer. or you can use this simple code but it dosen't work well.
public void slowMotion(){
final Handler handler = new Handler();
Runnable r = new Runnable() {
#Override
public void run() {
if (videoview != null) {
if (videoview.isPlaying()){
videoview.pause();
}
else{
videoview.start();
}
}
handler.postDelayed(this, 50);
}
};
handler.postDelayed(r, 800);
}
Good luck :D

Related

Control the playback time of a video

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);

Video player in android programming

Hi I wanna make a application by eclipse and I need to pause a Clip in a special time for example I wanna pause a clip in 2:30 and i don't know how can I do that please help me
Add following
videoView.postDelayed(new Runnable() {
#Override
public void run() {
videoView.pause();
}
}, 150000);

Playback video in slow motion in android

- I am working on a project which needs to play video in slow motion.
- I am well aware that Android doesn't provide these functionality.
- I found PVPlayer Engine and libVLC which possessed these capabilities, but i didn't found any tutorial or proper documentation of including them in the android project and using them.
- So i tried doing this by using Runnable and Handler, it was successful in slowing down the video but they possessed jerks during playing.
public class MainActivity extends Activity {
VideoView vx;
Button mbutt;
Handler h ;
int curr = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
h = new Handler();
vx = (VideoView)findViewById(R.id.videoView);
mbutt = (Button)findViewById(R.id.button_Play);
vx.setVideoPath("/mnt/sdcard/you.mp4");
mbutt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vx.start();
}
});
Runnable r = new Runnable() {
#Override
public void run() {
if (vx != null) {
if (vx.isPlaying()){
vx.pause();
}
else{
vx.start();
}
}
h.postDelayed(this, 50);
}
};
h.postDelayed(r, 200);
}
}
- I have tried various combination of pause time and playing time to remove the jerks but all in vain, can anyone help me in removing these jerks so it plays a nice slow motion video or suggest another easy to integrate library into my android project.
Thanks in advance......
I am late but I found a solution for API 23 and above. Android 6.0 added PlaybackParams class to control playback behavior. -
Use setPlaybackParams method of MediaPlayer as given below -
videoview = (VideoView)findViewById(R.id.videoview);
videoview.setVideoURI("Your Video URI");
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
//works only from api 23
PlaybackParams myPlayBackParams = new PlaybackParams();
myPlayBackParams.setSpeed(0.5f); //here set speed eg. 0.5 for slow 2 for fast mode
mp.setPlaybackParams(myPlayBackParams);
videoview.start();//start your video.
}
});
If you are searching how to embedded VLC into android, you can ref to this.
and you can change the speed by calling setRate(0.5f) to libVLC for slow motion.

How to play audio only from video file on Android?

I have mp4 and wmv movie files and need to play only sound not video screen. How to do it?? Could I get sound track from movie file??
I know if I hide the SurfaceView from screen, I can only hear sound.. but I have tried a lot but.. it is impossible.
If you have any solution to extract sound track from movie file, please let me know..
Thanks in advance.
If you are using the mediaplayer API in your app then don't call the API public void setDisplay (SurfaceHolder sh). This will ensure that only the audio is played out even if the video content is present..
More info in android doc here
Use following code, Optimize following code as per your requirement. It play video from youtube.
try {
final MediaPlayer m = new MediaPlayer();
Thread t = new Thread(new Runnable() {
public void run() {
try {
m.setDataSource("rtsp://v8.cache3.c.youtube.com/CjgLENy73wIaLwlQP1m32SiSYxMYJCAkFEIJbXYtZ29vZ2xlSARSB3JlbGF0ZWRggqG7w9aS2-1MDA==/0/0/0/video.3gp");
m.prepare();
m.start();
} catch (Exception e) {
e.printStackTrace();
}
}
});
t.start();
} catch (Exception e) {
e.printStackTrace();
}

Seamless video Loop with VideoView

I have the following code to take a video as a raw resource, start the video and loop it but I need the video to loop seamlessly as of now when it comes to an end of the clip and starts the clip again the transition between causes a flicker for a split second, which I really can't have for my app.
public class Example extends Activity {
VideoView vv;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vv = (VideoView)findViewById(R.id.VideoView01);
//Video Loop
vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
vv.start(); //need to make transition seamless.
}
});
Uri uri = Uri.parse("android.resource://com.example/"
+ R.raw.video);
vv.setVideoURI(uri);
vv.requestFocus();
vv.start();
}
}
The clip is only 22 seconds long but was created to be seamless so it is possible to work without the delay.
Try this it will work 100%
VideoView videoView;<---write this in outside of method or else declare it as final variable.
videoView.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
In Kotlin simply use
videoView.setOnPreparedListener { it.isLooping = true }
Not sure if this helps years later, but I used
vv.start();
vv.setOnCompletionListener ( new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
vv.start();
}
});
and it has a seamless loop
The pause is for the underlying MediaPlayer to refresh its buffers. How long that will take will depend on a number of factors, many of which are outside your control (e.g., speed of CPU, speed of on-board flash storage).
One you can control is to get your video out of the resource and into the filesystem. Resources are stored in the APK, which is a ZIP file, so extracting the video this way probably takes extra time.
You may need to switch away from VideoView and use a SurfaceView with two MediaPlayers, alternating between them -- one is playing while the next is preparing, so when the playing one ends you can switch to the new player. I have not tried this, and so I do not know what the ramifications might be. However, I know that this technique is frequently used for audio playback to transition from one clip to another.
Little late, but any reason that you can't use the following?
MediaPlayer.setLooping(true);
If you are using Kotlin
videoView.setOnPreparedListener(object : MediaPlayer.OnPreparedListener {
override fun onPrepared(mp: MediaPlayer?) {
//Start Playback
videoView.start()
//Loop Video
mp!!.isLooping = true;
Log.i(TAG, "Video Started");
}
});
Using Arrow Expression short form
videoView.setOnPreparedListener { mp ->
//Start Playback
videoView.start()
//Loop Video
mp!!.isLooping = true;
Log.i(TAG, "Video Started");
};
Answer to this is to remove the audio from the video and convert that to a .ogg file which can be looped seamlessly and then use the video without audio to loop round and this works.
Here is answer friends, you must use vv.resume in setOnCompletionListener class
[https://stackoverflow.com/a/27606389/3414469][1]

Categories

Resources