Objective
Although I disagree with you, I'll defend your right to speak to the!--Voltaire.
For a long time did not write the article, this topic in fact I want to write a very early, because from my first complete app project, almost every app has video playback needs, but I did not dare to start writing, because I think about video playback of the underlying technology implementation I still smattering. But still wrote this article, I hope that the great God can not hesitate to enlighten me, but also hope and I like the progress of the people can have some benefits, less detours, after reading this article can choose the most suitable for their own technology implementation program.
Bronze Age
Remember when you first learned iOS? At that time, it was amazing to have a few simple pieces of code to do all sorts of awesome functions. Video playback is also the case, open a few old iOS textbooks, you can see it in the directory. Yes, it is:
<MediaPlayer/MediaPlayer.h>
In the MediaPlayer framework, if you are lazy enough, you can use Mpmovieplayerviewcontroller to complete your playback function with three lines of code. However, look up to the big video app, and their playback interface is like this:
UC player. jpg
Look down at your player, but that's it:
Artistic requirements, do not take it seriously. png
Mom eggs, good low ah have wood, is can endure who cannot endure! Fortunately Apple has also provided us with a class MPMoviePlayerController, which allows us to customize the UI of the player, Recommended here is a domestic engineer open source based on the MPMoviePlayerController player Krvideoplayer, I believe that the majority of small partners needs can be solved perfectly.
Industrial Age
The wheels of history roll forward, never cease,
However MPMoviePlayerController custom players are not perfect:
- MPMoviePlayerController was abandoned by Apple in IOS9;
- When we need to deeply customize the player's needs, MPMoviePlayerController is not enough, such as the author before a voice-over software, need to play only video footage, without the need for video sound, but also need to turn on audio recording, And another audio player to play the background sound. This time, MPMoviePlayerController cried.
Given the limitations of <MediaPlayer/MediaPlayer.h>, the new framework emerges--avkit.
Avkit is a high-level object that is built on avfoundation to solve video playback. From the Avfoundation Programming Guide we can see a technology stack like this:
Screen shot 2016-03-22 pm 6.45.36.png
If someone remembers Avfoundation just out of that year's WWDC, must be impressed with the performance of Avfoundation, while playing 100 videos without the slightest! In the author's use process also verified this point, whether for the local video or network online on-demand, avfoundation performance is exceptionally excellent.
Let's look at the structure of Avkit first:
Avkit structure. png
As this article is only a "shopping guide" role, and about the avkit of related article documents a plethora therefore no longer introduced. Several third-party video frameworks based on Avkit are recommended below:
- Vkvideoplayer
- Almovieplayercontroller
- Pbjvideoplayer
Post-Industrial era
However, there will always be one, however, Avkit is not flawless, when we need to play some very standard video (such as RMVB), Avkit can only feel powerless.
Believing that Mac users are familiar with a VLC player, this player behaves exceptionally well on Mac, supporting formats that cover almost all formats (that's it!). )。 Yes, it's the creator--videolan, the open source of a video playing a game frame mobilevlckit!
Let's start by looking at the formats it supports:
. RMVB . asf . avi . dv . flv. gxf . m1v . m2v . m2ts. mkv . m OV . MP2 . mp4 . mpeg . MPEG1 . MPEG2 . MPEG4 . mpg. mts . MXF. ogg . og M. PS . ts . VOB . A52 . AC3 . DTS . FLAC . m4a. M4P . mka . MoD . Mp1. mp2 . mp3 *.ogg.
Isn't it very exciting? Then let's get started!
1. Framework Compilation
Before show you code, we always need to have its library first? The official gave a detailed tutorial, English is not good? FQ speed is not good? Never mind! There is a compiled VLC framework, download it!
Mobilevlckit Static Library Download link
2. Project compilation
Mobilevlckit's static library is very large, decompression down after almost 600+mb, but only a few m after compiling, so rest assured that use it.
Linked frameworks and libraries are added to download the completed Mobilevlckit;
To add a dependent framework, Mobilevlckit relies on the following framework:
Screen shot 2016-03-22 pm 8.11.05.png
- Modify the compilation options, because the framework is written by C + +, so we need to change the relevant compilation options;
6df02a9c-7e7a-422f-bf69-41f381f2659b.png
- Modify the framework Search Paths, otherwise the project cannot find the frame;
Cdfc9f51-d803-4376-a698-f29bdb542576.png
PS: "Std::ios_base::init::~init ()", referenced from
This compilation problem occurs, it is necessary to add libstdc++.dylib and libstdc++.6.dylib (for 6.1 use, XCODE5 after the default complier can also be compiled through)
Ok! Good surprise, CMD + B compiled successfully!
In order to offer my own. Based on the Mobilevlckit written by the player: Mrvlcplayer, originally I just Want to do a demo, but do think to make a framework, there are many features are not perfect, but as a demo should be enough.
Mrvlcplayer.gif Information Age
Of course, if you know some video decoding more professional knowledge, you can also use FFmpeg and live555, so you can learn more about the underlying video technology. Of course, Bo Master is now also learning this knowledge, this is only recommended to everyone, by the way quietly said, in fact, Mobilevlckit is based on the development of FFmpeg two times.
Stone Age PostScript
No matter how clever and obscure the technology is, the ultimate goal is to serve the people. Human evolution from the Stone Age to now, the hands of the tools for a stubble after another stubble, blindly dazzling technology does not make any sense, choose the right tool for their path. I believe that more than 90% of the demand, in this article before the information Age can be resolved, the choice of the right in your hands. Well, let's not say, I'm going to knock the female ape next to me into the cave, we'll see you next time.
Wen/maru (author of Jane's book)
Original link: http://www.jianshu.com/p/3618a9116660
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
Talking about the n solution of iOS video playback