android videoview播放进度,android – 获取视频播放视频的进度时间?
您可以通過mVideoView.getDuration()獲取視頻的持續(xù)時(shí)間,最初將Progress欄設(shè)置為0,然后通過mVideoView.getCurrentPosition()獲取視頻的currentProgress.并根據(jù)當(dāng)前視頻的百分比(%)增加(當(dāng)前* 100 /持續(xù)時(shí)間)的進(jìn)度條狀態(tài).我嘗試使用AsyncTask檢出這個(gè)完整的例子.
main.xml中
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:id="@+id/Progressbar"/>
VideoPlayActivity.java
public class VideoPlayActivity extends Activity {
ProgressBar mProgressBar;
VideoView mVideoView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String path = Environment.getExternalStorageDirectory().toString();
String filename = "/hr.3gp";
mProgressBar = (ProgressBar) findViewById(R.id.Progressbar);
mProgressBar.setProgress(0);
mProgressBar.setMax(100);
mVideoView = (VideoView) findViewById(R.id.my_Video_View);
mVideoView.setVideoURI(Uri.parse(path+filename));
new MyAsync().execute();
}
private class MyAsync extends AsyncTask
{
int duration = 0;
int current = 0;
@Override
protected Void doInBackground(Void... params) {
mVideoView.start();
mVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
duration = mVideoView.getDuration();
}
});
do {
current = mVideoView.getCurrentPosition();
System.out.println("duration - " + duration + " current- "
+ current);
try {
publishProgress((int) (current * 100 / duration));
if(mProgressBar.getProgress() >= 100){
break;
}
} catch (Exception e) {
}
} while (mProgressBar.getProgress() <= 100);
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
System.out.println(values[0]);
mProgressBar.setProgress(values[0]);
}
}
}
總結(jié)
以上是生活随笔為你收集整理的android videoview播放进度,android – 获取视频播放视频的进度时间?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: getLong java_java.la
- 下一篇: ug冲模标准件库_昆山兴模lt;携手gt