Let’s make a video player app

using VLC for iOS

Today, the term “open source” will have a meaning for you. We’re lucky that the people working hard on their projects allow others to move things to the next level. VLC is a nice open source project. We’re going to build it and create a framework which we can use the classes to utilize VLC abilities.

At first, you should clone the repository to a library directory. Open a terminal and navigate to a directory which your VLCKit will be downloaded.

git clone http://code.videolan.org/videolan/VLCKit.git

It’s totally easy to clone the VLCKit by using a command as above. Depending on your internet connection the download should be finished in few seconds. Navigate to the VLCKit directory where there is the script, buildMobileVLCKit.sh, you are able to execute by typing ./buildMobileVLCKit.sh. However don’t execute that command right now. Wait a moment and keep reading.

It may take minutes which gives a lot of time to smoke or have a coffee while waiting. Before enjoying that process let me explain what you are about to do. You’re about to build a static library for a real iOS device. The static libraries are statically linked to the project. Mostly, there is a need for a library for linking to the simulator. After finishing this build you can execute the command ./buildMobileVLCKit.sh -S for this aim. When you start writing the code of your app you will need to choose the library to link to the project. It might be a pain to change the library between the device and the simulator each time. So there is a command line tool which enables you to combine the libraries together.

lipo -create Release-iphoneos/libMobileVLCKit.a Release-iphonesimulator/libMobileVLCKit.a -o libMobileVLCKit.a

libMobileVLCKit.a is an all-in-one library — we call them ‘fat library’ — which you can use for both the real device and the simulator. During the development process you are able to use it without problems. However, for the release-app you should link the library which has been built only for the device. The reason is that the fat library is a large library in size. No one needs the processor instructions of the simulator for a real device. The app size is a crucial thing to consider for the mobile apps.

There is one more option that you can build a static framework with the command ./buildMobileVLCKit.sh -f. After getting done with the things above execute the command to build a framework. These processes takes a remarkable time and ends up with a huge library in size. When you’re done you’re going to see a message something like “MobileVLCKit.framework done”. Navigate to the build directory and copy-paste the MobileVLCKit.framework to somewhere you want to use from.

Start writing the project

In this part, we’re going to use the framework in a project and play a video inside the app. Create a project then drag and drop the framework into the project. Uncheck “Copy items if needed”. You should tell the path of the framework to the compiler. In Build Settings there is a key “Framework search paths”; enter the path of the framework as the value. Your basic ViewController.m file should look like the below code. But don’t run it now; because you have to do something lastly.

If you try to build the project you’re going to get a linking error. In Build Phases you have to include some libraries into the project. Under “Link Binary With Libraries” add libiconv.tbd, libc++.tbd, AudioToolBox.framework, VideoToolBox.framework, CoreMedia.framework, and CoreFoundation.framework.

Build the project and watch the movie! That’s all. Now, you can use all of the properties provided by the VLC in your project. The rest job is up to you.