The findViewById (int) method is undefined and the MediaController constructor is undefined

advertisements

I'm creating this fragment to stream video but I get two error stated that the method findViewById(int) is undefined and the constructor MediaController is undefined.

public class CommunityFragment extends Fragment  {

VideoView videoview;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View  v = inflater.inflate(R.layout.fragment_community, container, false);
    VideoView videoView=(VideoView)v.findViewById(R.id.VideoView);

    MediaController mediaController = new MediaController(getActivity().getApplicationContext());

    String str="http://202.73.9.10:1935/live2/smil:kctv_all.smil/playlist.m3u8";
    Uri uri = Uri.parse("first_uri");

    mediaController.setAnchorView(videoView);
        videoView.setVideoURI(uri);
        videoView.setMediaController(mediaController);
        videoView.start();
    return  v;
}
}


you have

VideoView videoView=(VideoView)getActivity().findViewById(R.id.VideoView);

and

videoview = (VideoView)findViewById(R.id.VideoView);

if VideoView belongs to the activity the first line is kind of ok, and you can delete the second one. It VideoView belongs to the Fragment, you can use

videoview = (VideoView)getView().findViewById(R.id.VideoView);

and get rid of the first one