我正在做一个基于视频视图的Android项目.我想在用户点击播放之前显示播放按钮,当用户决定暂停视频时 – 显示暂停按钮.单击暂停按钮应触发从暂停的同一位置再次播放视频(如YouTube视频).
im1.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { vv1.setVIDeoURI(Uri.parse("androID.resource://com.example.cm.filmfestival/" + R.raw.mission)); im1.setVisibility(VIEw.INVISIBLE); im2.setVisibility(VIEw.INVISIBLE); vv1.start(); }});im2.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { vv1.stopPlayback(); im2.setVisibility(VIEw.VISIBLE); im1.setVisibility(VIEw.INVISIBLE); }});@OverrIDepublic boolean ontouch(VIEw v, MotionEvent event) { im1.setVisibility(VIEw.VISIBLE); vv1.start(); im2.setVisibility(VIEw.VISIBLE); vv1.stopPlayback(); return true;}
解决方法:
请使用以下代码
<VIDeoVIEw androID:ID="@+ID/vIDeo_vIEw" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_gravity="center" /> public VIDeoVIEw myVIDeoVIEw; private int position = 0; private MediaController mediaControls; // set the media controller buttons if (mediaControls == null) { mediaControls = new MediaController(MainActivity.this); } // initialize the VIDeoVIEw myVIDeoVIEw = (VIDeoVIEw) findVIEwByID(R.ID.vIDeo_vIEw); try { // set the media controller in the VIDeoVIEw myVIDeoVIEw.setMediaController(mediaControls); // set the uri of the vIDeo to be played myVIDeoVIEw.setVIDeoURI(Uri.parse("your UrI")); } catch (Exception e) { Log.e("Error", e.getMessage()); e.printstacktrace(); } myVIDeoVIEw.requestFocus(); // we also set an setonPreparedListener in order to kNow when the vIDeo // file is ready for playback myVIDeoVIEw.setonPreparedListener(new OnPreparedListener() { public voID onPrepared(MediaPlayer mediaPlayer) { // if we have a position on savedInstanceState, the vIDeo // playback should start from here myVIDeoVIEw.seekTo(position); System.out.println("vidio is ready for playing"); if (position == 0) { myVIDeoVIEw.start(); } else { // if we come from a resumed activity, vIDeo playback will // be paused myVIDeoVIEw.pause(); } } });
总结 以上是内存溢出为你收集整理的如何在android中的视频视图中显示/隐藏播放/暂停按钮?全部内容,希望文章能够帮你解决如何在android中的视频视图中显示/隐藏播放/暂停按钮?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)