android, The constructor MediaController() is undefined

寵の児 提交于 2019-12-25 13:47:31

问题


I have an android app, working fine with fragments,

I need to show a video from a fragment, but in order to do this, I need to instantiate mediacontroller,

but i get :

The constructor MediaController() is undefined

here my code:

package com.orchard.elasto.custom;

import com.egoclean.elasto.R;

import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;


//public class VideoView {

public class VideoViewBox extends Fragment{

    // public MediaController mc;


    private MediaController mediaController = new MediaController(this); 



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


        //return inflater.inflate(R.layout.video_view, container,false);

        View view = inflater.inflate(R.layout.video_view, container,false);


           VideoView mVideo = (VideoView) view.findViewById(R.id.video_viewer);;



        mediaController.setAnchorView(mVideo);

      //Set video link (mp4 format )
//        Uri video = Uri.parse("android.resource://com.egoclean.elasto/raw/shoulder");

        Uri video = Uri.parse("android.resource://" + getClass().getPackage().getName() + "/" + R.raw.video1);


        mVideo.setMediaController(mediaController);
        mVideo.setVideoURI(video);
        mVideo.start();






        return view;

    }

}

so , how to instantiate my media controller?

thanks!


回答1:


Something like this maybe,

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



回答2:


Just

MediaController mediaController = new MediaController(getActivity());

works for me.



来源:https://stackoverflow.com/questions/11822843/android-the-constructor-mediacontroller-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!