The simplest ffmpeg-based mobile example attachment: iOS comes with a player

Source: Internet
Author: User
Tags vars

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.

Source

The source code for the project is in the Viewcontroller.m file, as shown in the following.

[OBJC]View PlainCopy
  1. /**
  2. * The simplest iOS video player
  3. * Simplest IOS Player
  4. *
  5. * Lei Hua Lei Xiaohua
  6. * [Email protected]
  7. * Communication University/Digital TV Technology
  8. * Communication University of China/digital TV Technology
  9. * http://blog.csdn.net/leixiaohua1020
  10. *
  11. * This program is the simplest video player on iOS.
  12. * This software are the simplest Video Player on IOS.
  13. *
  14. */
  15. #import "ViewController.h"
  16. #import <MediaPlayer/MediaPlayer.h>
  17. @interface Viewcontroller ()
  18. @property (nonatomic,Strong) MPMoviePlayerController *movieplayer; Video playback controller
  19. @end
  20. @implementation Viewcontroller
  21. -(void) Viewdidload {
  22. [Super Viewdidload];
  23. additional setup after loading the view, typically from a nib.
  24. [self. MoviePlayer Play];
  25. [self addnotification];
  26. }
  27. -(void) dealloc{
  28. //Remove all notification monitoring
  29. [[Nsnotificationcenter Defaultcenter] removeobserver: self];
  30. }
  31. -(MPMoviePlayerController *) movieplayer{
  32. if (!_movieplayer) {
  33. nsstring *urlstr=[[[nsbundle Mainbundle]resourcepath] stringbyappendingpathcomponent:@ "  Resource.bundle/war3end.mp4 "];
  34. nsurl *url=[nsurl fileurlwithpath:urlstr];
  35. _movieplayer=[[mpmovieplayercontroller Alloc]initwithcontenturl:url];
  36. _movieplayer. View.frame=self. View. Bounds;
  37. _movieplayer. View. autoresizingmask=uiviewautoresizingflexiblewidth|  Uiviewautoresizingflexibleheight;
  38. [self. View addsubview:_movieplayer. view];
  39. }
  40. return _movieplayer;
  41. }
  42. -(void) addnotification{
  43. nsnotificationcenter *notificationcenter=[nsnotificationcenter Defaultcenter];
  44. [Notificationcenter addobserver:self selector:@selector (mediaplayerplaybackstatechange:) name  : Mpmovieplayerplaybackstatedidchangenotification object:self. MoviePlayer];
  45. [Notificationcenter addobserver:self selector:@selector (mediaplayerplaybackfinished:) Name:  Mpmovieplayerplaybackdidfinishnotification object:self. MoviePlayer];
  46. }
  47. -(void) Mediaplayerplaybackstatechange: (nsnotification *) notification{
  48. switch (self. MoviePlayer. playbackstate) {
  49. case mpmovieplaybackstateplaying:
  50. NSLog (@ "playing ...");
  51. Break ;
  52. case mpmovieplaybackstatepaused:
  53. NSLog (@ "pause playback.");
  54. Break ;
  55. case mpmovieplaybackstatestopped:
  56. NSLog (@ "stop playing.");
  57. Break ;
  58. Default:
  59. NSLog (@ "playback status:%li",self. MoviePlayer. playbackstate);
  60. Break ;
  61. }
  62. }
  63. -(void) mediaplayerplaybackfinished: (nsnotification *) notification{
  64. NSLog (@ "play complete.%li",self. MoviePlayer. playbackstate);
  65. }
  66. -(void) didreceivememorywarning {
  67. [Super didreceivememorywarning];
  68. //Dispose of any resources, can be recreated.
  69. }
  70. @end
[OBJC]View PlainCopy

Run results

The app runs on the phone as shown in the results. 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

sourceforge:https://sourceforge.net/projects/simplestffmpegmobile/

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

The simplest ffmpeg-based mobile example attachment: iOS comes with a player

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.