2017-04-24 25 views
0

VideoViewのコントローラを自分で作成しています(Controllerを使用する方が簡単ですが、学校の宿題です)、アプリの外観は次のとおりです(VideoViewSeekBar私はこのコードAndroid VideoViewの再生時間が-1

VideoView vwVideo = (VideoView) findViewById(R.id.videoView); 
vwVideo.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.baby); 

SeekBar skbPosition = (SeekBar) findViewById(R.id.seekBarVideo); 
skbPosition.setMax(vwVideo.getDuration()); 

が、getDuration() retuを書いたonCreate方法で3 Buttons

(* .mp4、4.47 MB​​、00:01:44)ので、私はSeekBarの最大値を設定することに決めました。これが問題を解決する最善の方法であるかどうかはわかりません。

よりよい解決策はありますか?

答えて

1

動画の再生時間を取得するには、MediaMetadataRetrieverを使用します。

MediaMetadataRetriever retriever = new MediaMetadataRetriever(); 
//use setDataSource() functions to set your data source 
retriever.setDataSource(context, Uri.fromFile(videoFile)); 
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); 
long timeInMillisec = Long.parseLong(time); 

問題があれば私に更新してください。

関連する問題