### Install Homebrew, Git, and Yasm for Build Environment Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This section details the installation of essential build tools: Homebrew for package management on macOS, Git for version control, and Yasm for assembling x86-related code. It also includes instructions for setting environment variables for the Android SDK and NDK. ```bash # install homebrew, git, yasm ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew install git brew install yasm # add these lines to your ~/.bash_profile or ~/.profile # export ANDROID_SDK= # export ANDROID_NDK= # on Cygwin (unmaintained) # install git, make, yasm ``` -------------------------------- ### Install Homebrew and Git for iOS Development Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This command sequence installs Homebrew, a package manager for macOS, and Git. These are prerequisites for building ijkplayer on iOS, ensuring necessary tools are available. ```bash ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew install git ``` -------------------------------- ### Basic Video Playback with IjkMediaPlayer in Android Source: https://context7.com/bilibili/ijkplayer/llms.txt Implement basic video playback in an Android Activity using IjkMediaPlayer. This example demonstrates initializing the player, setting data sources, preparing asynchronously, and handling playback events like preparation, errors, completion, and buffering. ```java import tv.danmaku.ijk.media.player.IjkMediaPlayer; import tv.danmaku.ijk.media.player.IMediaPlayer; import android.view.SurfaceHolder; public class VideoPlayerActivity extends Activity implements SurfaceHolder.Callback { private IjkMediaPlayer mMediaPlayer; private SurfaceView mSurfaceView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mSurfaceView = findViewById(R.id.surface_view); mSurfaceView.getHolder().addCallback(this); // Initialize player mMediaPlayer = new IjkMediaPlayer(); mMediaPlayer.native_setLogLevel(IjkMediaPlayer.IJK_LOG_DEBUG); // Set listeners mMediaPlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() { @Override public void onPrepared(IMediaPlayer mp) { mp.start(); } }); mMediaPlayer.setOnErrorListener(new IMediaPlayer.OnErrorListener() { @Override public boolean onError(IMediaPlayer mp, int what, int extra) { Log.e("Player", "Error: " + what + ", " + extra); return true; } }); mMediaPlayer.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() { @Override public void onCompletion(IMediaPlayer mp) { Log.d("Player", "Playback completed"); } }); mMediaPlayer.setOnInfoListener(new IMediaPlayer.OnInfoListener() { @Override public boolean onInfo(IMediaPlayer mp, int what, int extra) { switch (what) { case IMediaPlayer.MEDIA_INFO_BUFFERING_START: Log.d("Player", "Buffering started"); break; case IMediaPlayer.MEDIA_INFO_BUFFERING_END: Log.d("Player", "Buffering ended"); break; case IMediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START: Log.d("Player", "Video rendering started"); break; } return true; } }); } @Override public void surfaceCreated(SurfaceHolder holder) { try { mMediaPlayer.setDisplay(holder); mMediaPlayer.setDataSource("https://example.com/video.mp4"); mMediaPlayer.prepareAsync(); } catch (IOException e) { e.printStackTrace(); } } @Override protected void onDestroy() { super.onDestroy(); if (mMediaPlayer != null) { mMediaPlayer.stop(); mMediaPlayer.release(); mMediaPlayer = null; } } } ``` -------------------------------- ### Build for iOS Source: https://context7.com/bilibili/ijkplayer/llms.txt Clones the ijkplayer repository, installs dependencies, initializes FFmpeg source, configures codec modules, and compiles FFmpeg for iOS. It also provides steps for opening the demo project in Xcode and integrating the framework into custom projects. ```bash # Clone repository git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios cd ijkplayer-ios git checkout -B latest k0.8.8 # Install dependencies brew install git yasm # Initialize FFmpeg source ./init-ios.sh # Configure codec modules (same options as Android) cd config rm module.sh ln -s module-lite.sh module.sh # Compile FFmpeg for iOS cd ../ios ./compile-ffmpeg.sh clean ./compile-ffmpeg.sh all # Build for all architectures # Open demo project in Xcode open IJKMediaDemo/IJKMediaDemo.xcodeproj # Integrate into your project: # 1. Select your project in Xcode # 2. File -> Add Files to... -> Select ios/IJKMediaPlayer/IJKMediaPlayer.xcodeproj # 3. Build Phases -> Target Dependencies -> Add IJKMediaFramework # 4. Build Phases -> Link Binary with Libraries -> Add: # - IJKMediaFramework.framework # - AudioToolbox.framework # - AVFoundation.framework # - CoreGraphics.framework # - CoreMedia.framework # - CoreVideo.framework # - libbz2.tbd # - libz.tbd # - MediaPlayer.framework # - MobileCoreServices.framework # - OpenGLES.framework # - QuartzCore.framework # - UIKit.framework # - VideoToolbox.framework ``` -------------------------------- ### Control IjkMediaPlayer Playback (Java) Source: https://context7.com/bilibili/ijkplayer/llms.txt Provides methods to control video playback, including starting, pausing, stopping, and resetting the player. It also allows seeking to specific positions, retrieving duration and current position, adjusting volume and playback speed, enabling looping, selecting audio tracks, and getting playback statistics. ```java IjkMediaPlayer player = new IjkMediaPlayer(); // Basic playback controls player.start(); // Start or resume playback player.pause(); // Pause playback player.stop(); // Stop playback player.reset(); // Reset player state player.release(); // Release all resources // Seek to position (milliseconds) player.seekTo(30000); // Seek to 30 seconds // Get playback information long duration = player.getDuration(); // Total duration in ms long position = player.getCurrentPosition(); // Current position in ms int width = player.getVideoWidth(); // Video width int height = player.getVideoHeight(); // Video height boolean playing = player.isPlaying(); // Playback state // Volume control (0.0 to 1.0) player.setVolume(0.5f, 0.5f); // Left and right channel volume // Playback speed control player.setSpeed(1.5f); // 1.5x playback speed float speed = player.getSpeed(0.0f); // Loop control player.setLooping(true); // Enable looping boolean looping = player.isLooping(); // Track selection IjkTrackInfo[] tracks = player.getTrackInfo(); for (int i = 0; i < tracks.length; i++) { int trackType = tracks[i].getTrackType(); if (trackType == ITrackInfo.MEDIA_TRACK_TYPE_AUDIO) { player.selectTrack(i); // Select this audio track } } int selectedAudio = player.getSelectedTrack(ITrackInfo.MEDIA_TRACK_TYPE_AUDIO); // Get statistics float decodeFps = player.getVideoDecodeFramesPerSecond(); float outputFps = player.getVideoOutputFramesPerSecond(); long bitRate = player.getBitRate(); long tcpSpeed = player.getTcpSpeed(); long videoCachedDuration = player.getVideoCachedDuration(); long audioCachedDuration = player.getAudioCachedDuration(); ``` -------------------------------- ### Implement IJKMediaPlayback Protocol for Player Control (Objective-C) Source: https://context7.com/bilibili/ijkplayer/llms.txt This snippet shows how to implement the IJKMediaPlayback protocol for managing player controls. It includes methods for setup, play, pause, stop, shutdown, checking if playing, seeking, background handling, thumbnail capture, and printing status information. This is useful for creating a reusable player management class. ```objc #import @interface PlayerManager : NSObject @property (nonatomic, strong) id player; @end @implementation PlayerManager - (void)setupPlayer:(NSURL *)url { IJKFFOptions *options = [IJKFFOptions optionsByDefault]; self.player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:options]; } // Playback controls - (void)play { [self.player play]; } - (void)pause { [self.player pause]; } - (void)stop { [self.player stop]; } - (void)shutdown { [self.player shutdown]; } - (BOOL)isPlaying { return [self.player isPlaying]; } // Seeking - (void)seekToTime:(NSTimeInterval)time { self.player.currentPlaybackTime = time; } // Background handling - (void)setPauseInBackground:(BOOL)pause { [self.player setPauseInBackground:pause]; } // Thumbnail capture - (UIImage *)captureCurrentFrame { return [self.player thumbnailImageAtCurrentTime]; } // Status information - (void)printStatus { NSLog(@"Duration: %.2f seconds", self.player.duration); NSLog(@"Current: %.2f seconds", self.player.currentPlaybackTime); NSLog(@"Playable: %.2f seconds", self.player.playableDuration); NSLog(@"Buffer: %ld%%", (long)self.player.bufferingProgress); NSLog(@"Size: %.0fx%.0f", self.player.naturalSize.width, self.player.naturalSize.height); NSLog(@"State: %ld", (long)self.player.playbackState); NSLog(@"Load: %lu", (unsigned long)self.player.loadState); NSLog(@"Bytes: %lld", self.player.numberOfBytesTransferred); NSLog(@"Ready: %@", self.player.isPreparedToPlay ? @"YES" : @"NO"); } @end ``` -------------------------------- ### Enable Debugging for ijkplayer Native Modules on Android Studio Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This command enables debugging for ijkplayer's native modules on Android Studio 2.2 and later using LLDB. It requires installing specific SDK tools like LLDB and NDK, then patching the project and configuring the debugger in Android Studio. ```bash sh android/patch-debugging-with-lldb.sh armv7a # Install Android Studio 2.2(+) # Preference -> Android SDK -> SDK Tools # Select (LLDB, NDK, Android SDK Build-tools,Cmake) and install # Open an existing Android Studio project # Select android/ijkplayer # Sync Project with Gradle Files # Run -> Edit Configurations -> Debugger -> Symbol Directories ``` -------------------------------- ### Add ijkplayer to Android Project via Gradle Source: https://context7.com/bilibili/ijkplayer/llms.txt Configure your project-level and app-level Gradle files to include ijkplayer dependencies. This setup supports multiple CPU architectures and optional backends like ExoPlayer. ```groovy // build.gradle (project level) allprojects { repositories { jcenter() } } // build.gradle (app level) dependencies { // Required - Java wrapper and ARMv7a native libraries compile 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8' compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8' // Optional - Additional CPU architectures compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.8.8' compile 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8' compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8' compile 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8' // Optional - ExoPlayer backend (experimental) compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.8.8' } ``` -------------------------------- ### Initialize Android Build Environment and Compile Source: https://context7.com/bilibili/ijkplayer/llms.txt Sets up the Android SDK and NDK environment variables, initializes FFmpeg source, configures codec modules, compiles FFmpeg, and compiles ijkplayer native libraries for Android. Ensure ANDROID_SDK and ANDROID_NDK are set in ~/.bash_profile. ```bash # Initialize Android build environment # Ensure ANDROID_SDK and ANDROID_NDK are set in ~/.bash_profile export ANDROID_SDK=/path/to/android-sdk export ANDROID_NDK=/path/to/android-ndk-r10e # Initialize FFmpeg source ./init-android.sh # Configure codec modules (choose one) cd config rm module.sh # Option 1: Default - full codec support ln -s module-default.sh module.sh # Option 2: Lite - smaller binary, common codecs only (default) ln -s module-lite.sh module.sh # Option 3: Lite + HEVC ln -s module-lite-hevc.sh module.sh # Compile FFmpeg cd ../android/contrib ./compile-ffmpeg.sh clean ./compile-ffmpeg.sh all # Build for all architectures # Or build specific architecture: # ./compile-ffmpeg.sh armv7a # ./compile-ffmpeg.sh arm64 # ./compile-ffmpeg.sh x86 # Compile ijkplayer native libraries cd .. ./compile-ijk.sh all # Open in Android Studio # File -> Open -> Select android/ijkplayer/ ``` -------------------------------- ### Build ijkplayer for Android Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This script sequence outlines the process for building the ijkplayer for Android. It includes cloning the repository, checking out a specific version, initializing Android build scripts, compiling FFmpeg, and finally compiling ijkplayer itself. ```bash git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android cd ijkplayer-android git checkout -B latest k0.8.8 ./init-android.sh cd android/contrib ./compile-ffmpeg.sh clean ./compile-ffmpeg.sh all cd .. ./compile-ijk.sh all ``` -------------------------------- ### Gradle Build for Android Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This snippet shows the command to navigate to the ijkplayer directory and initiate a Gradle build process for the Android project. This is a common step for building Android applications or libraries using Gradle. ```shell cd ijkplayer gradle ``` -------------------------------- ### Build IJKPlayer for Android from Source (Bash) Source: https://context7.com/bilibili/ijkplayer/llms.txt This bash script outlines the steps to clone the IJKPlayer repository and prepare it for building on Android. It includes cloning the repository, navigating into the directory, and checking out a specific version tag. This is the initial step for compiling the player from source for Android platforms. ```bash # Clone repository git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android cd ijkplayer-android git checkout -B latest k0.8.8 ``` -------------------------------- ### Build iOS Ijkplayer Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This snippet details the process of cloning the Ijkplayer repository, checking out a specific version, initializing iOS build scripts, and compiling FFmpeg for iOS. It also outlines the steps for integrating the compiled IJKMediaPlayer framework into an Xcode project. ```shell git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios cd ijkplayer-ios git checkout -B latest k0.8.8 ./init-ios.sh cd ios ./compile-ffmpeg.sh clean ./compile-ffmpeg.sh all ``` -------------------------------- ### Configure ijkplayer for Smaller Binary Size (Lite) Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This set of commands configures the ijkplayer build to use a 'lite' module configuration, reducing the binary size by removing less common FFmpeg components. It involves changing the `module.sh` symlink and cleaning the FFmpeg compilation. ```bash cd config rm module.sh ln -s module-lite.sh module.sh cd android/contrib # cd ios sh compile-ffmpeg.sh clean ``` -------------------------------- ### Configure ijkplayer for Full Codec/Format Support Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This configuration ensures that ijkplayer is built with the maximum set of codecs and formats supported by FFmpeg. It involves removing the default `module.sh` and linking to `module-default.sh`, followed by cleaning the FFmpeg compilation artifacts. ```bash cd config rm module.sh ln -s module-default.sh module.sh cd android/contrib # cd ios sh compile-ffmpeg.sh clean ``` -------------------------------- ### Configure ijkplayer for Smaller Binary Size (Lite with HEVC) Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This configuration optimizes ijkplayer for a smaller binary size while including HEVC (H.265) codec support. It modifies the `module.sh` symlink to `module-lite-hevc.sh` and then cleans the FFmpeg build artifacts. ```bash cd config rm module.sh ln -s module-lite-hevc.sh module.sh cd android/contrib # cd ios sh compile-ffmpeg.sh clean ``` -------------------------------- ### Android ijkplayer Gradle Dependencies Source: https://github.com/bilibili/ijkplayer/blob/master/README.md This snippet shows how to include ijkplayer as a dependency in an Android project using Gradle. It lists required and optional modules, including different CPU architectures and an experimental ExoPlayer backend. ```gradle allprojects { repositories { jcenter() } } dependencies { // required, enough for most devices. compile 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8' compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8' // Other ABIs: optional compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.8.8' compile 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8' compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8' compile 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8' // ExoPlayer as IMediaPlayer: optional, experimental compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.8.8' } ``` -------------------------------- ### Android Video Playback with IjkVideoView Source: https://context7.com/bilibili/ijkplayer/llms.txt Demonstrates how to use IjkVideoView in an Android Activity for video playback. It covers setting the render type, video path, and various playback listeners (prepared, completion, error). It also includes lifecycle management (onResume, onPause, onDestroy) and a method to toggle the video's aspect ratio. Dependencies include the IjkPlayer library. ```java import tv.danmaku.ijk.media.example.widget.media.IjkVideoView; import tv.danmaku.ijk.media.player.IMediaPlayer; public class VideoActivity extends Activity { private IjkVideoView mVideoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); mVideoView = findViewById(R.id.video_view); // Set render type mVideoView.setRender(IjkVideoView.RENDER_TEXTURE_VIEW); // or: mVideoView.setRender(IjkVideoView.RENDER_SURFACE_VIEW); // Set video path mVideoView.setVideoPath("https://example.com/video.mp4"); // or: mVideoView.setVideoURI(Uri.parse("content://...")); // Set listeners mVideoView.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() { @Override public void onPrepared(IMediaPlayer mp) { mVideoView.start(); } }); mVideoView.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() { @Override public void onCompletion(IMediaPlayer mp) { finish(); } }); mVideoView.setOnErrorListener(new IMediaPlayer.OnErrorListener() { @Override public boolean onError(IMediaPlayer mp, int what, int extra) { Toast.makeText(VideoActivity.this, "Playback error: " + what, Toast.LENGTH_SHORT).show(); return true; } }); } @Override protected void onResume() { super.onResume(); mVideoView.resume(); } @Override protected void onPause() { super.onPause(); mVideoView.pause(); } @Override protected void onDestroy() { super.onDestroy(); mVideoView.stopPlayback(); mVideoView.release(true); } // Toggle aspect ratio public void onToggleAspectRatio(View view) { int aspectRatio = mVideoView.toggleAspectRatio(); // Returns: AR_ASPECT_FIT_PARENT, AR_ASPECT_FILL_PARENT, // AR_ASPECT_WRAP_CONTENT, AR_16_9_FIT_PARENT, AR_4_3_FIT_PARENT } } ``` -------------------------------- ### Configure IjkMediaPlayer Hardware Decoding (Java) Source: https://context7.com/bilibili/ijkplayer/llms.txt Enables MediaCodec hardware decoding for improved performance and reduced battery consumption. It also configures audio output using OpenSL ES, sets the pixel format, enables frame dropping, and disables auto-start after preparation. Includes HTTP options and sets the data source. ```java IjkMediaPlayer ijkMediaPlayer = new IjkMediaPlayer(); // Enable hardware decoding with MediaCodec ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1); ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1); ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", 1); // Use OpenSL ES for audio output (lower latency) ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 1); // Set pixel format for video rendering ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32); // Enable frame dropping for smooth playback ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 1); // Disable auto-start after prepare ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0); // Skip loop filter for better performance (quality tradeoff) ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48); // HTTP options ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "http-detect-range-support", 0); // Set data source and prepare ijkMediaPlayer.setDataSource("rtmp://live.example.com/stream"); ijkMediaPlayer.prepareAsync(); ``` -------------------------------- ### Configure IJKPlayer with FFmpeg and Player Options (Objective-C) Source: https://context7.com/bilibili/ijkplayer/llms.txt This snippet demonstrates how to configure FFmpeg and player options for IJKPlayer using the IJKFFOptions class. It covers hardware decoding, media codec settings, frame dropping, seeking accuracy, frame rate limits, buffering, and timeout settings. Options can be set for player, format, and codec categories. ```objc #import IJKFFOptions *options = [IJKFFOptions optionsByDefault]; // Player options [options setPlayerOptionIntValue:1 forKey:@"videotoolbox"]; // Hardware decode [options setPlayerOptionIntValue:1 forKey:@"mediacodec"]; // Android MediaCodec [options setPlayerOptionIntValue:1 forKey:@"framedrop"]; // Drop frames on slow [options setPlayerOptionIntValue:0 forKey:@"start-on-prepared"]; // Don't auto-start [options setPlayerOptionIntValue:1 forKey:@"enable-accurate-seek"]; // Accurate seeking [options setPlayerOptionIntValue:30 forKey:@"max-fps"]; // Max frame rate [options setPlayerOptionIntValue:3 forKey:@"packet-buffering"]; // Buffer packets [options setPlayerOptionIntValue:50 forKey:@"min-frames"]; // Min buffered frames [options setPlayerOptionIntValue:0 forKey:@"infbuf"]; // Disable infinite buffer [options setPlayerOptionIntValue:256 forKey:@"max-buffer-size"]; // Max buffer 256KB // Format options [options setFormatOptionIntValue:10000000 forKey:@"analyzeduration"]; // Analysis duration [options setFormatOptionIntValue:1 forKey:@"flush_packets"]; // Flush packets [options setFormatOptionIntValue:0 forKey:@"http-detect-range-support"]; [options setFormatOptionValue:@"ijkplayer" forKey:@"user-agent"]; // HTTP User-Agent [options setFormatOptionIntValue:5000000 forKey:@"timeout"]; // Connection timeout // Codec options [options setCodecOptionIntValue:48 forKey:@"skip_loop_filter"]; // Skip loop filter [options setCodecOptionIntValue:8 forKey:@"skip_frame"]; // Skip non-reference // Initialize player with options NSURL *url = [NSURL URLWithString:@"https://example.com/stream.m3u8"]; IJKFFMoviePlayerController *player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:options]; // Set options after initialization [player setPlayerOptionIntValue:1 forKey:@"loop" ofCategory:kIJKFFOptionCategoryPlayer]; // Playback controls player.playbackRate = 1.5; // 1.5x speed player.playbackVolume = 0.8; // 80% volume player.scalingMode = IJKMPMovieScalingModeAspectFill; player.shouldAutoplay = YES; // Properties CGSize videoSize = player.naturalSize; NSTimeInterval duration = player.duration; NSTimeInterval currentTime = player.currentPlaybackTime; NSTimeInterval playable = player.playableDuration; int64_t bytesTransferred = player.numberOfBytesTransferred; float fps = player.fpsAtOutput; BOOL isHWDecoding = [player isVideoToolboxOpen]; ``` -------------------------------- ### Initialize and Control Video Playback with IJKFFMoviePlayerController in Objective-C Source: https://context7.com/bilibili/ijkplayer/llms.txt This Objective-C code snippet demonstrates how to initialize and configure IJKFFMoviePlayerController for video playback on iOS. It includes setting up hardware decoding, format options, and registering for playback state notifications. The player is configured with a video URL and added to the view hierarchy. ```objc #import @interface VideoPlayerViewController () @property (nonatomic, strong) IJKFFMoviePlayerController *player; @end @implementation VideoPlayerViewController - (void)viewDidLoad { [super viewDidLoad]; // Create options IJKFFOptions *options = [IJKFFOptions optionsByDefault]; // Enable hardware decoding (VideoToolbox) [options setPlayerOptionIntValue:1 forKey:@"videotoolbox"]; // Set format options [options setFormatOptionIntValue:1 forKey:@"dns_cache_clear"]; // Initialize player with URL and options NSURL *url = [NSURL URLWithString:@"https://example.com/video.mp4"]; self.player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:options]; // Configure player view self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.player.view.frame = self.view.bounds; self.player.scalingMode = IJKMPMovieScalingModeAspectFit; self.player.shouldAutoplay = YES; [self.view addSubview:self.player.view]; // Register for notifications [self registerNotifications]; // Prepare to play [self.player prepareToPlay]; } - (void)registerNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPreparedToPlay:) name:IJKMPMediaPlaybackIsPreparedToPlayDidChangeNotification object:self.player]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackStateDidChange:) name:IJKMPMoviePlayerPlaybackStateDidChangeNotification object:self.player]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackDidFinish:) name:IJKMPMoviePlayerPlaybackDidFinishNotification object:self.player]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerLoadStateDidChange:) name:IJKMPMoviePlayerLoadStateDidChangeNotification object:self.player]; } - (void)playerPreparedToPlay:(NSNotification *)notification { NSLog(@"Player prepared, duration: %.2f", self.player.duration); } - (void)playerPlaybackStateDidChange:(NSNotification *)notification { switch (self.player.playbackState) { case IJKMPMoviePlaybackStatePlaying: NSLog(@"Playing"); break; case IJKMPMoviePlaybackStatePaused: NSLog(@"Paused"); break; case IJKMPMoviePlaybackStateStopped: NSLog(@"Stopped"); break; default: break; } } - (void)playerPlaybackDidFinish:(NSNotification *)notification { int reason = [notification.userInfo[IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue]; switch (reason) { case IJKMPMovieFinishReasonPlaybackEnded: NSLog(@"Playback ended"); break; case IJKMPMovieFinishReasonPlaybackError: NSLog(@"Playback error"); break; case IJKMPMovieFinishReasonUserExited: NSLog(@"User exited"); break; } } - (void)playerLoadStateDidChange:(NSNotification *)notification { IJKMPMovieLoadState loadState = self.player.loadState; if (loadState & IJKMPMovieLoadStatePlayable) { NSLog(@"Playable"); } if (loadState & IJKMPMovieLoadStatePlaythroughOK) { NSLog(@"Playthrough OK"); } if (loadState & IJKMPMovieLoadStateStalled) { NSLog(@"Stalled"); } } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [self.player shutdown]; } @end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.