在Android中以慢动作播放视频 [英] Playback video in slow motion in android
问题描述
-我正在一个需要慢动作播放视频的项目.
- I am working on a project which needs to play video in slow motion.
-我很清楚Android不提供这些功能.
- I am well aware that Android doesn't provide these functionality.
-我发现拥有这些功能的 PVPlayer Engine 和 libVLC ,但是我没有找到任何包含它们的教程或适当的文档在android项目中并使用它们.
- 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.
-因此,我尝试使用Runnable
和Handler
来完成此操作,该方法成功降低了视频播放速度,但在播放过程中却出现了混蛋.
- 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);
}
}
-我尝试了各种不同的暂停时间和播放时间组合来消除抽搐,但徒劳无功,任何人都可以帮助我消除这些抽搐,以便播放一段不错的慢动作视频或建议另一个易于将库集成到我的android项目中.
- 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.
先谢谢了……
推荐答案
我来晚了,但是我找到了API 23及更高版本的解决方案. Android 6.0 添加了 PlaybackParams 类来控制播放行为. -
I am late but I found a solution for API 23 and above. Android 6.0 added PlaybackParams class to control playback behavior. -
使用MediaPlayer
的setPlaybackParams
方法,如下所示-
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.
}
});
这篇关于在Android中以慢动作播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!