我正在列出视频并在另一项活动中显示所选视频,并开始自动播放。
但我的座右铭是允许用户点击它,就像我们在许多移动应用中看到的那样。
其次,没有显示持续时间和进度
activity_single_contact.xml: -
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<VideoView
android:id="@+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="180dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</LinearLayout>
SingleContactActivity.java: -
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_contact);
// getting intent data
Intent in = getIntent();
String mobile = in.getStringExtra(TAG_URL);
Uri uri=Uri.parse(mobile);
VideoView video=(VideoView)findViewById(R.id.videoView1);
video.setVideoURI(uri);
video.start();
}
以及 如何通过搜索栏 显示视频的总持续时间和进度持续时间,就像我们通常在视频应用中看到的那样?
如何控制,点击播放和点击暂停,再次像其他视频应用一样!!!!
答案 0 :(得分:1)
现在,您正在onCreate功能中直接启动视频。您可以在布局中编写图像按钮。点击这些按钮即可编写视频开始代码。
示例:
<强> VideoPlayerActivity.java 强>
public class VideoPlayerActivity extends Activity {
private boolean mResumed = false;
private boolean mFocused = false;
private boolean mControlResumed = false;
private VideoView videoView = null;
private int stopPosition = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_TransparentVideo);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
setContentView(R.layout.video_view);
videoView =(VideoView)findViewById(R.id.myvideoview);
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.slow);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
}
@Override
public void onPause() {
super.onPause();
mResumed = false;
if (mControlResumed) {
if (null != videoView)
videoView.pause();
stopPosition = videoView.getCurrentPosition();
mControlResumed = false;
}
}
@Override
public void onResume() {
super.onResume();
mResumed = true;
if (mFocused && mResumed && !mControlResumed) {
if(null != videoView) {
//videoView.resume();
videoView.seekTo(stopPosition);
videoView.start();
}
mControlResumed = true;
}
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
mFocused = hasFocus;
if (mFocused && mResumed && !mControlResumed) {
if (null != videoView) {
//videoView.resume();
videoView.seekTo(stopPosition);
videoView.start();
}
mControlResumed = true;
}
}
}
现在从您的班级调用此活动:
Intent intent = new Intent();
intent.setClass(mContext, VideoPlayerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(intent);
答案 1 :(得分:1)
放置您的视频。启动触摸事件,例如按钮或其他内容,this链接可以帮助您持续时间