(Context, Token) in instantiating MediaController
Asked Answered
M

4

6

I am trying to add a mediaController in my VideoView. I am trying to follow the tutorial in this site.

However, I am having an error in my class in this line.

MediaController mediaController = new MediaController(this);

The error says,

MediaController (Context, Token) in MediaController cannot be applied to (MainActivity)

What is the Token parameter? Its been a while since I have coded in Native Android and I think I missed some necessary details and changes.

EDIT I was looking in a different tutorial, the one in the link, is Made in Android Studio. My Mistake.

My Class

public class MainActivity extends ActionBarActivity {
public VideoView videoOne;
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    videoOne = (VideoView) findViewById(R.id.videoView);
    videoOne.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video1));
    videoOne.start();

    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoOne);
    videoOne.setMediaController(mediaController);

    videoOne.setOnPreparedListener(new MediaPlayer.OnPreparedListener()  {
        @Override
        public void onPrepared(MediaPlayer mp) {
            Log.i("Video Duration", "Duration = " + videoOne.getDuration());
        }
    });
    videoOne.setMediaController(mediaController);

}
Metic answered 12/2, 2015 at 5:58 Comment(0)
T
35

The error is pretty straightforward. Make sure you are importing the correct MediaController. For your purpose you need this import:

import android.widget.MediaController;

The above class has the constructor you are looking for. The link:

http://developer.android.com/reference/android/widget/MediaController.html#MediaController(android.content.Context)

You might be using the one below:

 import android.media.session.MediaController;

Hope this helps

Tachymetry answered 12/2, 2015 at 6:25 Comment(0)
D
2

this one solve my 'this' issue

import import android.widget.MediaController;
Dupre answered 30/4, 2015 at 12:22 Comment(0)
M
1

I solved it. I imported android.media.session.MediaController instead of android.widget.MediaController

Metic answered 12/2, 2015 at 6:30 Comment(0)
M
0
 videoview.setOnPreparedListener(new OnPreparedListener() { 
        @Override 
        public void onPrepared(MediaPlayer mp) {
                mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() { 
                                                @Override 
                                                public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
                                                        /* 
                                                         *  add media controller 
                                                         */ 
                                                        mc = new MediaController(YourActivity.this);;
                                                        videoview.setMediaController(mc); 
                                                        /* 
                                                         * and set its position on screen 
                                                         */ 
                                                        mc.setAnchorView(videoview); 
                                                    } 
                                                }); 
                                            } 
                                        }); 
Muskrat answered 12/2, 2015 at 6:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.