preface

I may not agree with what you say but I will defend to the death your right to say it! — voltaire

I haven’t written an article for a long time. In fact, I wanted to write about this topic for a long time. Since my first complete APP project, almost every APP has the requirement of video playing, but I hesitated to write because I still had a little knowledge of the underlying technology of video playing. But I still wrote this article, hoping that the great god passing by can be generous to give advice, but also hope that people like me who are making progress can benefit, less detours, after reading this article can choose the most suitable for their own technical implementation plan.

The Bronze Age

Remember when you first learned iOS? At that time, I was amazed that all kinds of awesome functions could be done with a few simple lines of code. The same goes for video playback, which you can find in the catalog if you flip through a few old iOS textbooks. Yes, it is:

In the frame of the MediaPlayer, if you are lazy, then use MPMoviePlayerViewController three lines of code you can finish your playback function. However, if you look up at all the video apps, the screen looks like this:




UC player.jpg

I looked down at my player and saw something like this:




Art request, don’t take it seriously

Damn it, it’s so Low, it’s unbearable! Fortunately, Apple also provides us with a class called MPMoviePlayerController that allows us to customize the UI of the player, Here I recommend KRVideoPlayer, an open source MPMoviePlayerController player based on domestic engineers. I believe that most of your needs can be perfectly solved.

The industrial age

The wheel of history rolls on and never stops,

However, the MPMoviePlayerController custom player isn’t perfect:

  1. MPMoviePlayerController was deprecated by Apple in iOS9;
  2. The MPMoviePlayerController can’t do much when we need to deeply customize the player. For example, when I was making a dubbing software, I only needed to play the image of the video without the sound of the video, and at the same time, I needed to start recording the audio and start another audio player to play the background sound. At this point, the MPMoviePlayerController is crying.

Given these limitations, a new framework has emerged –AVKit.

AVKit is a high-level object for video playback built on AVFoundation. AVFoundation Programming Guide:




Screen shot 2016-03-22 PM 6.45.36.png

If anyone remembers AVFoundation’s WWDC the year it was released, they must have been impressed with AVFoundation’s performance, playing 100 videos at once without any lag! This has also been verified in my use of AVFoundation, which performs exceptionally well both for local video and online on-demand.

Let’s take a look at AVKit’s structure first:




AVKit structure. PNG

Since this article is just a “guide” and there are so many articles and documents about AVKit, I won’t cover them. Here are a few avKit-based third-party video frameworks:

  1. VKVideoPlayer
  2. ALMoviePlayerController
  3. PBJVideoPlayer

Post-industrial age

However, AVKit isn’t perfect, and when it comes to playing video in unconventional formats (such as RMVB), AVKit is out of luck.

Mac users will probably be familiar with a VLC player that works exceptionally well on the Mac and supports almost every format (that’s awesome!). . Yes, the creator of VideoLAN has open-source MobileVLCKit, an awesome video streaming framework.

Let’s take a look at the formats it supports:

.rmvb .asf .avi .divx .dv .flv .gxf .m1v .m2v .m2ts .m4v .mkv .mov .mp2 .mp4 .mpeg .mpeg1 .mpeg2 .mpeg4 .mpg .mts .mxf .ogg .ogm .ps .ts .vob .wmv .a52 .aac .ac3 .dts .flac .m4a .m4p .mka .mod .mp1 .mp2 .mp3 *.ogg.

Is it very enchanted? Let’s get started!

1. Framework compilation

Before we Show you code, we need to have a library for it, right? The official has given a detailed tutorial, not good English? Bad Internet speed over the wall? It doesn’t matter! Here is the compiled VLC framework, just download it!

MobileVLCKit static library download link

2. Project compilation

MobileVLCKit’s static library is very large, almost 600+MB when unpacked, but only a few megs when compiled, so feel free to use it.

  1. Add the MobileVLCKit download to the Linked Frameworks and Libraries;

  2. Add a dependency framework, MobileVLCKit relies on the following framework:




Screen shot 2016-03-22 PM 8.11.05.png

  1. Change the compilation options. Since the framework is written in C++, we need to change the relevant compilation options.



6DF02A9C-7E7A-422F-BF69-41F381F2659B.png

  1. Modify Framework Search Paths, otherwise the project cannot find the Framework.



CDFC9F51-D803-4376-A698-F29BDB542576.png

PS: “STD ::ios_base::Init::~Init()”, referenced from add libstdc++.dylib and libstdc++.6.dylib. Xcode5 can also be compiled with default complier.

OK! CMD + B compiled successfully.

In order to draw inspiration, I present my own player based on MobileVLCKit: MRVLCPlayer, ORIGINALLY I just want to do a Demo, but I am trying to make it into a framework, there are still many functions not perfect, but as a Demo should be enough.




MRVLCPlayer.gif

The information age

Of course, if you know some more professional knowledge of video decoding, you can also use FFMPEG and Live555, so that you can learn more low-level video related technology. Of course, the blogger is also learning this knowledge, here is just recommended to everyone, incidentally, in fact MobileVLCKit is based on FFMPEG secondary development.

Stone Age Postscript

No matter how awesome or obscure the technology, the ultimate purpose is to serve people. As humans evolved from the Stone Age to today, the tools in our hands have changed one after another. There is no point in just showing off your skills. I believe that more than 90 percent of these needs can be solved before the information age of this article. The choice is yours. Good don’t say, I want to stun my mother ape next to drag into the cave, we see next time ~