我正在使用Fragment,我想在其中播放视频。方法videoView.setOnCompletionListener(getActivity());
存在问题。它表示VideoView类型中的方法setOnCompletionListener(MediaPlayer.OnCompletionListener)不适用于参数(FragmentActivity)。这是我的代码:
public class my_Fragment extends Fragment implements
AdapterView.OnItemSelectedListener, OnCompletionListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.my_layout, container, false);
VideoView videoView = (VideoView)v.findViewById(R.id.videoView1);
MediaController mc = new MediaController(getActivity());
//videoView.setMediaController(mc);
videoView.setKeepScreenOn(true);
videoView.setVideoPath("android.resource://com.my.package/raw/"+R.raw.myvideo);
videoView.start();
videoView.requestFocus();
videoView.setOnCompletionListener(getActivity());
mFlipper = ((ViewFlipper) v.findViewById(R.id.flipper));
mFlipper.startFlipping();
Spinner s = (Spinner) v.findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_spinner_item, mStrings);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
s.setOnItemSelectedListener(this);
return v;
}