Everyone roar, unknown program monkey guo students again bubble, today is the leading role is: the industry well-known, the biggest different (tong) sex dating platform, BILIBILI open source video player project, based on FFMPEG IJKPlayer<(~ ~)/··· questions collection! Well, I believe that just out of the weekend, work in two days, not in the mood pulled eggs, because… pull it hurt more Σ (° ° | | |) ︴, let’s begin.

1. IJKPlayer does not rotate the video Angle like the system player, so you need to go to onInfo what == iMediaPlayer. MEDIA_INFO_VIDEO_ROTATION_CHANGED to get the Angle and rotate the screen yourself. Or open hard hard decoding, not hard decoding easy to cause black screen silence, you are careful ah O__O “… .

mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec".1);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate".1);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change".1);Copy the code

2, IJKPlayer appears black with sound and no image, check your video encoding is H264, pixel format exists, audio encoding is AAC? IJKPlayer does not support 3PG by default. , does not support MEPG4 (such as this library RecordVideoDemo), does not support AMR. So if you really want support, refer to this #1961, turn on MPEG4 support, reprogram FFMPEG, and then play MPEG4 by hard decoding; Or through the system to record VideoRecord; Or choose another JAVACV to record and encapsulate FFmpegRecorder.

ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec".1);
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec_mpeg4".1);Copy the code

3, fast forward and slow play interface, only support API23 above, 23 below, it is necessary to configure ffmpeg to support avfilter, but there may be voice tremor and other problems, the official said unstable, refer to #1690.

Tryavfilter but the audio sounds shaking = =

For avfilter, only support software decoder.Copy the code

4, Pause, back to the background and then back to the foreground, the screen black? GetBitmap (point. X, point. Y); Get the paused image, display it with ImageView, hide the ImageView when onSurfaceTextureUpdated to connect the image.

5. Some video return codes

int MEDIA_INFO_VIDEO_RENDERING_START = 3;// The video is ready to render
int MEDIA_INFO_BUFFERING_START = 701;// Start buffering
int MEDIA_INFO_BUFFERING_END = 702;// Buffering ends
int MEDIA_INFO_VIDEO_ROTATION_CHANGED = 10001;// Video select information
int MEDIA_ERROR_SERVER_DIED = 100;// Video interrupts. Generally, the video source is abnormal or the video type is not supported.
int MEDIA_ERROR_IJK_PLAYER = - 10000..// Usually there is a problem with the video source or the data format is not supported, such as the audio is not AAC, etc
int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200;// Data errors have no valid collectionCopy the code

6, some video in the SeekTo, will drag the position before the jump, this is because the problem of key frames of video, popular is not compatible with FFMPEG, video compression is too severe, the seek only supports the key frames, this case is the original video file I frame is relatively small, players will find the latest key frames in the position of the drag, Currently, IJKPlayer has no solution.

The download speed can be obtained from IjkMediaPlayer getTcpSpeed.

8, high resolution open hard decoding, if not supported will automatically switch to soft solution, even if open Mediacodec, if the device does not support, the display of the decoder is avCodec soft solution.

9, ijkMediaPlayer.setOption can be configured with the corresponding header file refer to ff_ffplay_options.

10. If the buffer progress bar is less than 100, I will not guarantee 100, so I usually do:

// The number 95 May be inaccurate and may need to be lower in some cases
if (secProgress > 95) secProgress = 100;Copy the code

There is no problem with IJK EXOPlayer and MediaPlayer. They are better than IJKPlayer in compatibility, but they are not as good as IJK in details, such as EXOPlayer: The problem of returning to the foreground and switching the rendering control’s black screen for a period of time is that I have found no other way but to use Seekto. This experience led me to choose IJKPlayer.

Overall, Google is stronger in compatibility, but IJKPlayer handles well in details. Here, one player is compatible with video, while the other is compatible with video. See your personal preference.