如何在播放视频时使视频按钮始终出现? 现在该按钮仅在我们单击视频时出现,请帮助我 这是我的代码。
MainActivity.java
val vidAddress = "http:lalala.com/ikon.mp4"
val vidUri = Uri.parse(vidAddress)
val fullScreen = intent.getStringExtra("fullScreenInd")
if ("y" == fullScreen) {
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
supportActionBar?.hide()
}
myVideo.setVideoURI(vidUri)
val mediaController = FullScreenVideo(this)
mediaController.setAnchorView(myVideo)
myVideo.setMediaController(mediaController)
myVideo.start()
mediaController.requestFocus()
FullscreenVideo
Class FullScreenVideo(context:Context):MediaController(context){
private var fullScreen: ImageButton? = null
private var isFullScreen: String? = null
override fun setAnchorView(view: View) {
super.setAnchorView(view)
//image button for full screen to be added to media controller
fullScreen = ImageButton(super.getContext())
val params = FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
params.gravity = Gravity.RIGHT
params.rightMargin = 80
addView(fullScreen, params)
//fullscreen indicator from intent
isFullScreen = (context as Activity).intent.getStringExtra("fullScreenInd")
if ("y" == isFullScreen) {
fullScreen!!.setImageResource(R.drawable.ic_minimize)
} else {
fullScreen!!.setImageResource(R.drawable.ic_fullscreen)
}
//add listener to image button to handle full screen and exit full screen events
fullScreen!!.setOnClickListener {
val intent = Intent(context, MainActivity::class.java)
if ("y" == isFullScreen) {
intent.putExtra("fullScreenInd", "")
} else {
intent.putExtra("fullScreenInd", "y")
}
(context as Activity).startActivity(intent)
}
}
}
答案 0 :(得分:0)
您可以设计自己的播放按钮,而不是使用Videoview播放按钮。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/video_frame"
android:layout_width="fill_parent"
android:layout_height="480px"
android:background="#000"
>
<VideoView
android:id="@+id/video_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ImageButton
android:id="@+id/play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:src="@drawable/ic_launcher"
/>
</FrameLayout>
mPlayButton = (ImageButton) findViewById(R.id.play_button);
mPlayButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mPlayer.isPlaying()) {
resetPlayer();
} else {
playVideo(videoUrl, mVideoView.getHolder());
// show the media controls
mController.show();
// hide button once playback starts
mPlayButton.setVisibility(View.GONE);
}
}
});