Since Apple supports only a few video and audio codecs, I was looking for a a/v framework for a new TVOS application. Videolan (creators behind the VLC player) providing a framework called TVVLCKit. I’m writing this article because I’ve spent a lot of time getting them working.
There are two ways to get the framework:
First is to easily download the nightly build: http://nightlies.videolan.org/build/tvOS/
Then drag and drop the framework to your project and add it to the Linked Frameworks and Libraries. In my test project this produced an error during the start of the application in the simulator. After reading the log files of the simulator I found out, that it’s missing an “Info.plist” file in the framework: Failed to load Info.plist from bundle at path
To solve this I copied the latest file from the git repository into the framework folder: https://code.videolan.org/videolan/VLCKit/blob/master/Resources/DynamicTVVLCKit/Info.plist
Second variant is to compile it yourself. You can follow the instructions of the wiki article from videolan.
For both variants you need to do the following steps, to use it in your swift project:
- Create a Bridging-Header file and add them in the Build Settings to the “Objective-C Bridging Header”
- Import TVVLCKit.h in the bridging header
- #import <TVVLCKit/TVVLCKit.h> when using the Framework
- #import “TVVLCKit/VLCMediaPlayer.h” when using the self compiled variant
- Add libc++.tbd and libiconv.tbd in the build phase “Linked Framework and Libraries”
Now you can use the player framework in your project by adding following sample code in the viewDidLoad():
let mediaPlayer = VLCMediaPlayer() mediaPlayer.drawable = videoView // videoView is the UIView that should draw the window mediaPlayer.media = VLCMedia(url: URL(string: "http://myURL")!) mediaPlayer.play()
When you now build the project, you might run into some compiler errors, e.g.:
Undefined symbols for architecture x86_64: "_AudioConverterReset", referenced from: _ffat_decode_flush in TVVLCKit(audiotoolboxdec.o) "_AudioConverterDispose", referenced from: _ffat_close_decoder in TVVLCKit(audiotoolboxdec.o) "_AudioConverterFillComplexBuffer", referenced from: _ffat_decode in TVVLCKit(audiotoolboxdec.o)
This means, that you need to add additional frameworks (in this case the audiotoolboxdec.o is missing). Find the matching framework (most a similar name) and add them to your project in the “Linked Framework and Libraries” section. Usually you need the following:
- AVFoundation
- AudioToolbox
- CoreMedia
- VideoToolbox
Hi!
Great to see your interest in deploying TVVLCKit in your own apps. Did you consider using our cocoapod “TVVLCKit-unstable”? It’s name is more scary than what it may sound like as it is exactly what we deploy in the official VLC-tvOS app as well as various further apps. This should automagically solve your deployment issues as long as you are statically linking the framework. For now, we don’t have a cocoapod for a dynamic framework due to lack of interest from third parties. We’d be happy to add one if there is need.
Regarding the Info.plist issue, we will have a look! Is there anything else you discovered in TVVLCKit or you having problems with?
Cheers from VideoLAN,
Felix
Hey Felix,
I’m not using CocoaPods because of the Ruby requirement on the Mac. That’s why I’m going the “classic” way and add frameworks manually to my projects.
The framework itself is great, so thanks for working on it.
Regards,
Martin
I have a problem… 🙁
:0: error: generate-pch command failed with exit code 1 (use -v to see invocation)
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
Just FYI. The Info.plist issue is still a thing (3.3.2 version).
I need to manually copy it out of the repo, rename, it and add it to the Carthage download.
Not a big deal to do, but sloppy configuration management, on my part. Shouldn’t be a part of my workflow.