Giter Site home page Giter Site logo

linsea / universalvideoview Goto Github PK

View Code? Open in Web Editor NEW
988.0 57.0 271.0 463 KB

A better Android VideoView with more Media Controller customization. 一个更好用的Android VideoView

Home Page: https://github.com/linsea/UniversalVideoView

Java 100.00%
videoview video universalvideoview player mediaplayer fullscreen auto-switching media-player media

universalvideoview's Introduction

Android UniversalVideoView

中文版说明请点击这里

UniversalVideoView is a Android widget helps playing video easier, which is similar with the Android system native VideoView, but providing more customization feature: fitXY or keeping aspect ratio fullscreen videoView, auto switch to fullscreen on landscape mode, customised control UI...

Sample Screenshot 1 Sample Screenshot 2

Usage

For a working implementation of this project see the sample app.

  1. add library dependency to your build.gradle file.
            dependencies {
                compile 'com.linsea:universalvideoview:1.1.0@aar'
            }
  1. Include the UniversalVideoView and UniversalMediaController widget in your layout. This should usually be placed in the same parent ViewGroup, which makes sense when in full screen state.
            <FrameLayout
                android:id="@+id/video_layout"
                android:layout_width="fill_parent"
                android:layout_height="200dp"
                android:background="@android:color/black">

                <com.universalvideoview.UniversalVideoView
                    android:id="@+id/videoView"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_gravity="center"
                    app:uvv_autoRotation="true"
                    app:uvv_fitXY="false" />

                <com.universalvideoview.UniversalMediaController
                    android:id="@+id/media_controller"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    app:uvv_scalable="true" />

            </FrameLayout>
  1. In your onCreate method, set the UniversalMediaController to the UniversalVideoView and implements the UniversalVideoView.VideoViewCallback Callback.
            View mBottomLayout;
            View mVideoLayout;
            UniversalVideoView mVideoView;
            UniversalMediaController mMediaController;

            mVideoView = (UniversalVideoView) findViewById(R.id.videoView);
            mMediaController = (UniversalMediaController) findViewById(R.id.media_controller);
            mVideoView.setMediaController(mMediaController);

            mVideoView.setVideoViewCallback(new UniversalVideoView.VideoViewCallback() {
                @Override
                public void onScaleChange(boolean isFullscreen) {
                    this.isFullscreen = isFullscreen;
                    if (isFullscreen) {
                        ViewGroup.LayoutParams layoutParams = mVideoLayout.getLayoutParams();
                        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
                        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
                        mVideoLayout.setLayoutParams(layoutParams);
                        //GONE the unconcerned views to leave room for video and controller
                        mBottomLayout.setVisibility(View.GONE);
                    } else {
                        ViewGroup.LayoutParams layoutParams = mVideoLayout.getLayoutParams();
                        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
                        layoutParams.height = this.cachedHeight;
                        mVideoLayout.setLayoutParams(layoutParams);
                        mBottomLayout.setVisibility(View.VISIBLE);
                    }
                }

                @Override
                public void onPause(MediaPlayer mediaPlayer) { // Video pause
                    Log.d(TAG, "onPause UniversalVideoView callback");
                }

                @Override
                public void onStart(MediaPlayer mediaPlayer) { // Video start/resume to play
                    Log.d(TAG, "onStart UniversalVideoView callback");
                }

                @Override
                public void onBufferingStart(MediaPlayer mediaPlayer) {// steam start loading
                    Log.d(TAG, "onBufferingStart UniversalVideoView callback");
                }

                @Override
                public void onBufferingEnd(MediaPlayer mediaPlayer) {// steam end loading
                    Log.d(TAG, "onBufferingEnd UniversalVideoView callback");
                }

            });

Note

  • Support Android Gingerbread V2.3(API Level 9 and above).
  • UniversalVideoView does not retain its full state when going into the background. You should save or restore the state and take care of the Activity Lifecycle.
  • You may need to set the android:configChanges="orientation|keyboardHidden|screenSize" for your Activity in AndroidManifest.xml to prevent the system from recreate the Activity while phone rotation.

Customization

UniversalVideoView attribute

  • uvv_fitXY, Video scale to fill the VideoView's dimension or keep Aspect Ratio (default) likes Android framework VideoView.
  • uvv_autoRotation, auto switch to landscape(fullscreen) or portrait mode according to the orientation sensor.

UniversalMediaController attribute

  • uvv_scalable, show or hide the scale button. if you will not play the video in fullscreen.

TODO

  • Brightness control on UniversalMediaController.
  • Volume Control on UniversalMediaController.

License

Copyright 2015 The UniversalVideoView author <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

universalvideoview's People

Contributors

linsea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

universalvideoview's Issues

Cannot resume video player when stream url reconnect

This is my code to handle video player when stream url reconnect. When i click play video on media controller, video player cannot resume:

mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@OverRide
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
position = mediaPlayer.getCurrentPosition();
mMediaController.hideError();
mVideoView.stopPlayback();
return true;
}
});
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@OverRide
public void onPrepared(MediaPlayer mediaPlayer) {
if (position > 0) {
mediaPlayer.seekTo(position);
}
}
});

当按下home键的时候

视频正在播放的时候
按下home键 并不能保存当前状态
在onSaveInstanceState中调用的 时候
mVideoView.getCurrentPosition() 为 0
在surfaceholder 的 ondestory中调用的 时候
mVideoView.getCurrentPosition() 也为 0

Brightness for video

Hi, I've used universal video view in my fire tv app.
How can maintain the brightness of video view?
Please let me know. Thanks

播放器隐藏时可能出现mMediaController为null

UniversalVideoView line 844 mMediaController.toggleButtons(fullscreen);
这里mMediaController有可能为null
具体场景:有些页面需要播放视频,有些页面不需要.通过是否有是否有视频url决定是否隐藏播放器.当隐藏播放器时,mMediaController值并没有被设置,当屏幕选择时,mMediaController为null,导致程序崩溃.

暂停有延迟

点击暂停会有延迟,就是要等1`2s才暂停下来,是怎么回事呢?

Full Screen

Video can't play when i click to icon full at right screen.

Loading progress title

Hi @linsea , thanks for your awesome lib. Can you please provide me instruction how to change progress loading title. To see image please check attachments. Thanks!
title_player

自动旋转不完善

在手机里,手机开启自动旋转之后旋转不能全屏。
模拟器里旋转屏幕也不能全屏。我修改了下OrientationDetector里判断方向的代码

  if (orientation > 350 || orientation < 10) { //0度
                        if (currentOrientation != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
                            Log.d(TAG, "switch to SCREEN_ORIENTATION_PORTRAIT");
                            currentOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                            if (listener != null) {
                                listener.onOrientationChanged(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, currDirection);
                            }
                        }
                    } else if (orientation > 80 && orientation < 100) { //90度
                        currentOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                        if (listener != null) {
                            listener.onOrientationChanged(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, currDirection);
                        }
                    } else if (orientation > 170 && orientation < 190) { //180度
                        if (currentOrientation != ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
                            Log.d(TAG, "switch to SCREEN_ORIENTATION_REVERSE_PORTRAIT");
                            currentOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
                            if (listener != null) {
                                listener.onOrientationChanged(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, currDirection);
                            }
                        }
                    } else if (orientation > 260 && orientation < 280) { //270度
                        if (currentOrientation != ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
                            Log.d(TAG, "switch to SCREEN_ORIENTATION_REVERSE_LANDSCAPE");
                            currentOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
                            if (listener != null) {
                                listener.onOrientationChanged(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, currDirection);
                            }
                        }
                    }

然后在AndroidManifest里screenOrientation改成sensor。就可以真自动旋转全屏了。
不知道这样改对不对,可是却是可以自动旋转全屏

Fullscreen button has to be pressed twice to enter full screen

Im trying to use your video view but when i press the full screen button, the orientation changes but it is a not truly full screen. The bottom and top layouts are off screen, and then when i press the fullscreen button again the video goes full screen as expected.

Iv tried to debug the code but can't see where this is happening, the setfullscreen method is called as usual but it seems that it needs to be called twice.

Help would be appreciated

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.