项目作者: linsea

项目描述 :
A better Android VideoView with more Media Controller customization. 一个更好用的Android VideoView
高级语言: Java
项目地址: git://github.com/linsea/UniversalVideoView.git


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.
    1. dependencies {
    2. compile 'com.linsea:universalvideoview:1.1.0@aar'
    3. }
  2. 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.

    1. <FrameLayout
    2. android:id="@+id/video_layout"
    3. android:layout_width="fill_parent"
    4. android:layout_height="200dp"
    5. android:background="@android:color/black">
    6. <com.universalvideoview.UniversalVideoView
    7. android:id="@+id/videoView"
    8. android:layout_width="fill_parent"
    9. android:layout_height="fill_parent"
    10. android:layout_gravity="center"
    11. app:uvv_autoRotation="true"
    12. app:uvv_fitXY="false" ></com.universalvideoview.UniversalVideoView>
    13. <com.universalvideoview.UniversalMediaController
    14. android:id="@+id/media_controller"
    15. android:layout_width="fill_parent"
    16. android:layout_height="fill_parent"
    17. app:uvv_scalable="true" ></com.universalvideoview.UniversalMediaController>
    18. </FrameLayout>
  3. In your onCreate method, set the UniversalMediaController to the UniversalVideoView and implements the UniversalVideoView.VideoViewCallback Callback.

    1. View mBottomLayout;
    2. View mVideoLayout;
    3. UniversalVideoView mVideoView;
    4. UniversalMediaController mMediaController;
    5. mVideoView = (UniversalVideoView) findViewById(R.id.videoView);
    6. mMediaController = (UniversalMediaController) findViewById(R.id.media_controller);
    7. mVideoView.setMediaController(mMediaController);
    8. mVideoView.setVideoViewCallback(new UniversalVideoView.VideoViewCallback() {
    9. @Override
    10. public void onScaleChange(boolean isFullscreen) {
    11. this.isFullscreen = isFullscreen;
    12. if (isFullscreen) {
    13. ViewGroup.LayoutParams layoutParams = mVideoLayout.getLayoutParams();
    14. layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    15. layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
    16. mVideoLayout.setLayoutParams(layoutParams);
    17. //GONE the unconcerned views to leave room for video and controller
    18. mBottomLayout.setVisibility(View.GONE);
    19. } else {
    20. ViewGroup.LayoutParams layoutParams = mVideoLayout.getLayoutParams();
    21. layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    22. layoutParams.height = this.cachedHeight;
    23. mVideoLayout.setLayoutParams(layoutParams);
    24. mBottomLayout.setVisibility(View.VISIBLE);
    25. }
    26. }
    27. @Override
    28. public void onPause(MediaPlayer mediaPlayer) { // Video pause
    29. Log.d(TAG, "onPause UniversalVideoView callback");
    30. }
    31. @Override
    32. public void onStart(MediaPlayer mediaPlayer) { // Video start/resume to play
    33. Log.d(TAG, "onStart UniversalVideoView callback");
    34. }
    35. @Override
    36. public void onBufferingStart(MediaPlayer mediaPlayer) {// steam start loading
    37. Log.d(TAG, "onBufferingStart UniversalVideoView callback");
    38. }
    39. @Override
    40. public void onBufferingEnd(MediaPlayer mediaPlayer) {// steam end loading
    41. Log.d(TAG, "onBufferingEnd UniversalVideoView callback");
    42. }
    43. });

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

  1. Copyright 2015 The UniversalVideoView author <dictfb@gmail.com>
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.