Location>code7788 >text

FFmpeg development notes (fifty-two) mobile domestic video player GSYVideoPlayer

Popularity:712 ℃/2024-09-08 13:51:52
GSYVideoPlayer is a domestic video player for mobile, which uses four player kernels, including IJKPlayer, Media3(EXOPlayer), MediaPlayer, AliPlayer, etc. It supports pop-ups, filters, advertisements and many other features.

GSYVideoPlayer's Github page is /CarGuo/GSYVideoPlayer, as of August 18, 2024, the project has 20,000 Github stars and 0.42 million copies, which is quite good, knowing that the FFmpeg project only has 44,400 stars on Github in the same period. This is quite a good result.
However, if you integrate GSYVideoPlayer in your app project, you should pay attention to the environment configuration to avoid import failure. The specific import procedure is described below:

I. Installing Android Studio Jellyfish

Although the homepage of GSYVideoPlayer does not specify in which version of Android Studio to import the library, but in practice, we found that even the Android Studio Dolphin (small dolphin version) launched two years ago can not import GSYVideoPlayer properly, let alone the earlier Android Studio, let alone earlier versions of Android Studio.
If you want to import and call GSYVideoPlayer successfully, you need to install a newer version of Android Studio, such as the Jellyfish version of Android Studio Jellyfish. although the Jellyfish version of the new app project is encoded in Kotlin, GSYVideoPlayer supports Java encoding, so you can still call GSYVideoPlayer in Java code. So you can still call GSYVideoPlayer in Java code.

Second, modify the configuration of the App project

First open the App project's and add the following two lines of repository configuration inside the repositories node in order to pull the GSYVideoPlayer library from the specified repository.

maven { url '' }
maven { url "/repository/public" }

Next, open the App module's and internally add the following configuration inside the dependencies node to indicate the introduction of version 9.0.0 of the GSYVideoPlayer library.

// be in favor ofJava
implementation ':gsyVideoPlayer-java:v9.0.0-release-jitpack'
// be in favor ofExoPlayerparadigm
implementation ':GSYVideoPlayer-exo2:v9.0.0-release-jitpack'
// be in favor ofAliPlayerparadigm
implementation ':GSYVideoPlayer-aliplay:v9.0.0-release-jitpack'
// be in favor ofarm64instruction set
implementation ':gsyVideoPlayer-arm64:v9.0.0-release-jitpack'

Then open the App module's and add the following internet permission configuration:

<uses-permission android:name="" />

After completing the above three configuration changes, you can only use GSYVideoPlayer's player control in the app code.

Third, the use of the player in the App code

GSYVideoPlayer provides three kinds of player controls, namely NormalGSYVideoPlayer, GSYADVideoPlayer and ListGSYVideoPlayer, and their usage in the app code are described below:

1、Ordinary Player NormalGSYVideoPlayer

NormalGSYVideoPlayer is used to play a single video file. The code for placing this control in an XML file is shown below:

<
    android:
    android:layout_width="match_parent"
    android:layout_height="300dp" />

2. Advertisement Player GSYADVideoPlayer

GSYADVideoPlayer is used to play advertisements in the opening credits of a video file. Note that this control should be used in conjunction with NormalGSYVideoPlayer. The code for placing the control in the XML file is shown below:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <
        android:
        android:layout_width="match_parent"
        android:layout_height="300dp" />
    <
        android:
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:visibility="gone" />
</RelativeLayout>

3、ListGSYVideoPlayer

ListGSYVideoPlayer is used to play a number of video files in a chronological list. The code for placing this control in an XML file is shown below:

<
    android:
    android:layout_width="match_parent"
    android:layout_height="300dp" />

After placing any one of the above three player controls in the XML file, then go back to the Java code to perform the video playback operation. Taking NormalGSYVideoPlayer as an example, the code example for playing a single video file through Java is as follows:

private static String URL_MP4 = "/fs/transcode/20240520/8cc/355193-1716184798-transv.mp4";
private NormalGSYVideoPlayer video_player;
private OrientationUtils orientationUtils;

@Override
protected void onCreate(Bundle savedInstanceState) {
    (savedInstanceState);
    setContentView(.activity_simple_player);
    video_player = findViewById(.video_player);
    // Setting the rotation
    orientationUtils = new OrientationUtils(this, video_player);
    // Setting up full-screen key functions,This is using the selection screen,Instead of full screen
    video_player.getFullscreenButton().setOnClickListener(v -> {
        // No screen rotation required,It is also necessary to set the setNeedOrientationUtils(false)
        ();
    });
    // No screen rotation required
    video_player.setNeedOrientationUtils(false);
    findViewById(.btn_play_mp4).setOnClickListener(v -> {
        video_player.setUp(URL_MP4, true, "Digital China Summit Welcome Song");
    });
}

Then run the test app and observe the effect of NormalGSYVideoPlayer playing network video as shown below:

Because NormalGSYVideoPlayer's playback kernel is based on IJKPlayer, EXOPlayer and AliPlayer, which support HLS, RTMP and other live links by default, there is no need to change the code, just change the video address to HLS link ending with m3u8 or RTMP link starting with rtmp, then you can let the NormalGSYVideoPlayer to play live content. The effect of using NormalGSYVideoPlayer to play live video is shown below:

For more details on FFmpeg development seeFFmpeg Development in Action: From Zero Basics to Short Video OnlineA book.