Android Media Controller FullScreen Button

时间:2015-07-28 16:19:52

标签: android video android-studio mediacontroller android-fullscreen

I have managed to follow the tutorial from this link: http://www.brightec.co.uk/ideas/custom-android-media-controller The only thing new that I have added is this block of code in the VideoPlayerAcitivity:

@Override
public void toggleFullScreen() {

    DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
    android.widget.FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) videoSurface.getLayoutParams();
    params.width =  metrics.widthPixels;
    params.height = metrics.heightPixels;
    params.leftMargin = 0;
    videoSurface.setLayoutParams(params);

}

Everything in the controller works besides the fullscreen buttons. When I click on the fullscreen button in the beginning, it expands the view and the video becomes bigger. However, the fullscreen button icon does not change. It stays at the ic_media_fullscreen_stretch icon. Even when I click it again, it does not manage to change back. Not only is this the problem, but I also want to have it so that when you click on the full screen button, it automatically takes you into landscape mode so that the video is not stretched like it is in portrait mode. I have also seen that when I go into landscape mode in my emulator, the video restarts which it should not (I have already tried adding android:configChanges="orientation|screenSize" into the manifest yet it does not work), and the fullscreen button disappears from the media controller. I think this is because the width of the media controller goes over the screen and I have no idea how to fix this. I have done a lot of research on the media controllers, and I keep coming back to different websites displaying practically the same tutorial. I tried setting this media controller up on a separate activity so that I could test it out in the beginning and see if it worked. Yet I am eventually going to put it onto another activity of mine. I am guessing that I just need to implement the surface view into the place of the video view I have there currently, and then add the java code for VideoPlayerActivity into that activities java file. Is this correct? Because I still have other views on that layout that I still want displayed and to be working. Help would be very much appreciated! Sorry for the multiple questions.

0 个答案:

没有答案