The previous articles recorded the FFmpeg-based multimedia programs under iOS. This document records a video player that comes with iOS. Compared to porting FFmpeg, iOS comes with a multimedia frame that is much easier to play video--just a few interfaces to call.
The source code of the project is in the Viewcontroller.m file, as shown in the following.
/** * The simplest iOS video player * simplest iOS player * * Lei hua Lei Xiaohua * [email protected] * Communication University/Digital TV technology * Communication Univ Ersity of China/digital TV technology * http://blog.csdn.net/leixiaohua1020 * * This program is the simplest video player on iOS. * This software are the simplest Video Player on IOS. * */#import "ViewController.h" #import <MediaPlayer/MediaPlayer.h> @interface Viewcontroller () @property ( Nonatomic,strong) MPMoviePlayerController *movieplayer;//video playback controller @end@implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Additional setup after loading the view, typically from a nib. [Self.movieplayer play]; [Self addnotification]; }-(void) dealloc{//Remove all notification monitoring [[[Nsnotificationcenter Defaultcenter] removeobserver:self];} -(MPMoviePlayerController *) movieplayer{if (!_movieplayer) {nsstring *urlstr=[[[nsbundle mainBundle]resourcePa TH] stringbyappendingpathcomponent:@ "Resource.bundle/war3end.mp4"]; Nsurl *url=[nsurl Fileurlwithpath:urlSTR]; _movieplayer=[[mpmovieplayercontroller Alloc]initwithcontenturl:url]; _movieplayer.view.frame=self.view.bounds; _movieplayer.view.autoresizingmask=uiviewautoresizingflexiblewidth| Uiviewautoresizingflexibleheight; [Self.view Addsubview:_movieplayer.view]; } return _movieplayer;} -(void) addnotification{nsnotificationcenter *notificationcenter=[nsnotificationcenter DefaultCenter]; [Notificationcenter addobserver:self selector: @selector (mediaplayerplaybackstatechange:) Name: Mpmovieplayerplaybackstatedidchangenotification Object:self.moviePlayer]; [Notificationcenter addobserver:self selector: @selector (mediaplayerplaybackfinished:) Name: Mpmovieplayerplaybackdidfinishnotification Object:self.moviePlayer]; }-(void) Mediaplayerplaybackstatechange: (nsnotification *) notification{switch (self.moviePlayer.playbackState) { Case Mpmovieplaybackstateplaying:nslog (@ "playing ..."); Break Case MpmovieplaybackstatepaUsed:nslog (@ "pause playback."); Break Case Mpmovieplaybackstatestopped:nslog (@ "stop playing."); Break Default:nslog (@ "Playback status:%li", self.moviePlayer.playbackState); Break }}-(void) mediaplayerplaybackfinished: (nsnotification *) notification{NSLog (@ "Play done.%li", Self.moviePlayer.playbackState);} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
The results of running the results app on your phone are as shown in. After the program runs, the War3end.mp4 file in Resource.bundle is automatically played.
Download
simplest ffmpeg Mobile
Project Home
Github:https://github.com/leixiaohua1020/simplest_ffmpeg_mobile
Open source China: https://git.oschina.net/leixiaohua1020/simplest_ffmpeg_mobile
CSDN Project: http://download.csdn.net/detail/leixiaohua1020/8924391
This solution contains various examples of using FFMPEG to process multimedia on the mobile side:
[Android]
Simplest_android_player: Android interface-based video player
Simplest_ffmpeg_android_helloworld: FFmpeg-based HelloWorld program under Android platform
Simplest_ffmpeg_android_decoder: The simplest ffmpeg-based video decoder on the Android platform
Simplest_ffmpeg_android_decoder_onelib: The simplest ffmpeg-based video decoder on the Android Platform-Library edition
Simplest_ffmpeg_android_streamer: The simplest ffmpeg-based push-to-flow device under the Android platform
Simplest_ffmpeg_android_transcoder: FFmpeg command-line tool ported under Android platform
Simplest_sdl_android_helloworld: The simplest program for porting SDL to the Android platform
[IOS]
Simplest_ios_player: Video player based on iOS interface
HelloWorld program based on FFmpeg under the Simplest_ffmpeg_ios_helloworld:ios platform
The simplest ffmpeg-based video decoder under the Simplest_ffmpeg_ios_decoder:ios platform
The simplest ffmpeg based on the Simplest_ffmpeg_ios_streamer:ios platform
FFMPEG.C command-line tool ported under Simplest_ffmpeg_ios_transcoder:ios Platform
Simplest_sdl_ios_helloworld: The simplest program to migrate SDL to the iOS platform
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The simplest ffmpeg-based mobile example attachment: iOS comes with a player