Preface
Today, I will share with you an open source multi-function video player —GSYVideoPlayer, supports many functions such as barrage, filters, watermarks, gif screenshots, opening credits, sound, brightness adjustment, etc., here we use it to implement a standard video player. So, without further ado, Go ~
GSYVideoPlayer A player based on IJkPlayer
Supports adjusting sound brightness
Cache while playing and using AndroidVideoCache; ExoPlayer uses SimpleCache
Supports multiple protocols h263\4\5, Https, concat, rtsp, hls, rtmp, crypto, mpeg, etc.
Simple filters (mosaic, black and white, color filtering, Gaussian, blur, blur, etc. More than 20 kinds), animation, (watermark, multi-screen playback, etc.)
Video first frame and video frame screenshot function, video generation gif function.
Adjust the display ratio: default, 16:9, 4:3, fill; rotate the picture angle during playback (0,90,180,270); mirror rotation
IJKPlayer, EXOPlayer, MediaPlayer switching, custom kernel
Small windows, small windows under multiple forms (including desktops) play.
Opening ads, skip ad support, and insert ads in the middle.
Pause the front and backstage switching without black screen; adjust the support for different clarity; seamless switching support; lock/unlock the full screen click function; preview of the progress bar window
Custom rendering layer, custom management layer, custom playback layer (control layer), custom cache layer
Introduce dependencies
maven { url '' }
maven { url "/repository/public" }
//Introduced in the full version
implementation ':GSYVideoPlayer:v8.3.3-release-jitpack'
//Is AliPlayer mode required
implementation ':GSYVideoPlayer-aliplay:v8.3.3-release-jitpack'
Development Settings
Set the configChanges and screenOrientation of the Activity
<activity android:name=".MainActivity" android:exported="true" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode" android:screenOrientation="fullSensor" > <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> </activity>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro xmlns:app="/apk/res-auto" xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> < android: android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
Set up the link to play the video
videoPlayer = findViewById() (videoUrl, true, "title")
If you want to add a video cover, you can set it like this
val coverImg = ImageView(this) () = coverImg
Specific implementation
Hide the included title and return key
= =
Set rotation, horizontal screen display
orientationUtils = OrientationUtils(this, videoPlayer) { () }
Start playing
()
In addition, you need to deal with the life cycle
override fun onPause() { () () } override fun onResume() { () () } override fun onDestroy() { () () () }
When in landscape screen, if you want to click the return key to return to the vertical screen instead of exiting, you need to rewrite onBackPressed
override fun onBackPressed() { if ( == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { () return } (null) () }
If the video is displayed in the form of a list, it is OK. First, create a RecyclerView
<?xml version="1.0" encoding="utf-8"?> < xmlns:andro xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".VideoListActivity"> < android: android:layout_width="match_parent" android:layout_height="match_parent" /> </>
Write item layout
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="30dp"> < android: android:layout_width="match_parent" android:layout_height="300dp" /> </LinearLayout>
RecyclerView Adapter
class VideoAdapter(private val urlList: List<String>, private val context: Context) : <>() { inner class ViewHolder(view: View) : (view) { val itemPlayer: StandardGSYVideoPlayer = (.item_player) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val view = (context).inflate(.item_video, parent, false) return ViewHolder(view) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { //Configure StandardGSYVideoPlayer with() { setUpLazy(urlList[position], true, null, null, "title") //Hide title and return key = = //Full screen key { (context, false, true) } //Prevent misalignment settings playPosition = position //Whether to automatically select horizontal and vertical full screen according to the video size, according to the video size isAutoFullWithSize = true // Whether to release when the audio focus conflicts isReleaseWhenLossAudio = false //Full screen animation isShowFullAnimation = true //Not touch and slide setIsTouchWiget(false) } } override fun getItemCount() = }
Activity
val videoRecyclerView = findViewById<RecyclerView>(.video_recyclerView) val layoutManager = LinearLayoutManager(this, , false) = layoutManager //Collection of video links val videoAdapter = VideoAdapter(, this) = videoAdapter (object : () { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { (recyclerView, dx, dy) //The first item of the visible area val firstPosition = () //The last item of the visible area val lastPosition = () //The play location val playPosition = ().playPosition if (playPosition >= 0) { //Indicates that there is playback if (playPosition < firstPosition || playPosition > lastPosition) { if ((this@VideoListActivity)) { return } () () } } } })
Don't forget to deal with the return key and life cycle
override fun onBackPressed() { () if ((this)) { return } () } override fun onPause() { () () } override fun onResume() { () () } override fun onDestroy() { () () }
This is the article about the development process of the Android multi-function video player GSYVideoPlayer. For more information about Android GSYVideoPlayer, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!