我正在尝试在Android工作室制作媒体控制器,但使用片段而不是活动,我使用下面的代码,但它给了我以下错误:
public class Tab1Helloworld extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab1helloworld, container, false);
return rootView;
VideoView video = (VideoView)rootView.findViewById(R.id.videoView);
video.requestFocus();
String videopath = "android.resource://com.r.teamkape.kiddiecodiel/" + R.raw.helloworldvid;
video.setVideoURI(Uri.parse(videopath));
video.setMediaController(new MediaController(this)); //error in (this)[enter image description here][1]
video.requestFocus();
video.start();
}
}
3 回答
@xhen,使用下面的代码这完美,
in xml layout add this
in your Fragment class call these medthods
将此
mBinding.videoview
替换为您的video
对象 . Now, Create CustomVideoView class您添加的错误的问题
在这一行
更换
同
也动了
在启动视频后到方法结束