Through Google’s Summer of Code Program, I was allowed to work on VLC under the mentorship of Diogo Simao Marques and Felix Paul Kühne
Though I had contributed to the VLC-iOS project before, working on the GSoC project was full of ups and downs.
My Project Goals:
To Save the Local Media, VLC on iOS uses VLCMediaLibraryKit, which wraps a C++ library deployed across all VLC's platforms, thus enabling access to various APIs, for features like metadata parsing, saving playback state, caching the thumbnailing of media, etc.
Currently, tvOS doesn't use this library but a very basic implementation class, thus no support for the above things.
My Project revolved around writing the UI via UIKit and also beginning the compilation via VLCMediaLibraryKit, thus exposing these features to tvOS.
Enabling the Compilation:
The initial phase of integration began by adapting the MediaLibraryService class, a fundamental component that interfaces with VLCMediaLibraryKit, for compatibility with both iOS and tvOS platforms. To accomplish this, adjustments were made to the codebase, focusing on the search paths crucial for media scanning operations. Notably, a key divergence was identified between tvOS and iOS in terms of storage conventions. While iOS relies on the Document Directory, tvOS employs the Cache Directory.
Whenever a new media is added, the VLCMediaLibraryKit is capable of identifying its type, name, duration, etc. and all the data models for different types of media such as Video, Audio, and Playlists are notified by the MediaLibraryService, So that they can be updated with new data.
The next step involved the compilation of these models for tvOS, as well as modifying them to be compatible with Objective C code, as most of the UI on tvOS is written in this language, and UI interacts with models instead of MediaLibraryService mostly to fetch the data.
Each Model and UI follows an observer design pattern to inform for changes in the data. I Had to work on a swift helper class for these observers to work properly with Objective C code.
Finally, reworking VLCAppCoordinator for tvOS which can be used to access a common instance of media library service anywhere in the code
Reworking the UI, addition of new features:
The way to add local media to VLC's tvOS is via the Remote Playback feature, which then displays the media items in a collection view, in the remote playback view controller.
My work involved reworking this view controller and class so that it integrates with the data models properly and also constructing new UIs to expose more features of the VLCMediaLibrary kit
Things I worked on in this class:
Separate tab for audio and video media:
Before, all the media were shown together whether audio or video in the collection view.
Initially, I planned on doing a Separate Audio and Video Controller and integrating them with their respective data models, however, this doesn't seem a much better approach because writing the same collection view code again for each view controller would have introduced a lot of unnecessary code
Finally, I found a way to reuse the collection view implemented in VLCRemotePlaybackView.
I introduced a tab bar in this view controller and added custom code which upon switching fetches the data from the audio/video model and repopulates the very same collection view.
Deletion and Renaming the media items:
This involved changes to VLCDeletionCapableViewController, a class that takes care of actions performed by the user on an Apple TV remote. to launch alerts for rename and deletion.
This class is inherited by VLCRemotePlaybackView, where the actual deletion / rename happens, and data models and collection view is updated.
Reworking the Collection View Cell:
As access to media's metadata is enabled by VLCMediaLibraryKit, I modified the cell to add a progress view, a 'new media' label and the desired properties and method etc to properly reflect the cell's media metadata.
Continue where left off feature :
This feature already existed on iOS, where users can resume the video/audio where they last left.
I worked on bringing this on tvOS, which required changes to VLCPlaybackService, a class that manages the playback of media in the codebase.
Caching of media's thumbnail:
Each time a new media is added, we can generate a thumbnail for it to be displayed on its cell using VLCMediaLibraryKit. However, generating a new thumbnail every time can be expensive performance-wise. Thus, I worked on thumbnail cache, which utilises NSCache to save the thumbnails.
Adding support for sorting:
VLCMediaLibraryKit supports the ability to sort media items by their date of addition, duration, file size, play count etc. in ascending or descending order.
The next thing I worked on was adding support for this on tvOS, and exposing this via UI.
However, Doing this in Objective C couldn't happen because VLCMLSorting types weren't exposable to Objective C.
I did a swift class to handle this. This also made the sort alert a reusable component as now I can you same code for both playlist and audio/video items.
Support for Playlists:
The next thing I worked on was adding support for the creation of playlists and UI to display them.
This was divided into a series of steps.
Edit Selection Mode for RemotePlaybackView:
To create playlists, the user should be able to select the media items in a row, to do this, I had to rework the collection view cells again to display media items with a check mark, when selected, and write code to handle the UI behaviour required for an edit selection mode. I maintain an NSHashMap that stores the selected cell and its corresponding VLCMLMedia.
Add to Playlist View:
From the selected media items I present a view that shows a UITableView that shows the existing playlist so that the user can add the media instead of creating a new one.
Otherwise, I added a button that lets the user create a new playlist after presenting a UIAlert for entering the playlist's name.
The Main Playlist UI:
To work on this view, I started by creating a new XIB and its view controller in Swift.
My View was mainly populated with a UITableView, that's filled with UITableViewCells, representing each playlist that exists.
To Work on the Cell, I created its Custom Class and XIB the cell consists of the playlist's thumbnail, name, duration, and number of tracks it consists of.
Finally wrote the logic, to integrate it with the table view.
Additional View to show Playlist's Media Items:
This view presents the playlist items. I reused VLCRemoteCells already used in VLCRemotePlaybackView to present in this view. I was thinking of reusing VLCCollectionViewController by inheriting from that class and thus preventing rewriting logic for the collection view population.
However, this made it integrating with VLCDeletionCapableViewController quite curbsome though I could still view and play media items.
Thus to make the deletion and rename functionality work, I added my custom collection view and inherited my class from VLCDeletionCapableViewController.
Support for Searching through Media, and Playlists:
During my final week in GSoC, I worked on adding support to search media, playlists through a collection.
This required me to add a text field as UI component in every view controller that required this feature , I utilised the UIKit text field delegate methods to retrieve search results , maintain an array for searched items retrieved the item via VLCMediaLibraryKit api.
I then wrote the logic for how would I update the collection view based on the search results.
Deletion and rename while searching
I extended the searching feature to more useful if user could search and rename a media item / playlist while searching.
This required changes to deletion and rename methods , so that I can provide the search data source to them and things accordingly.
Minor Feature addition:
VLC ForceRescan:
This feature lets user reset the files and media and launches a rescan for new files.
As this exists in the settings portion of the app , I Modified VLCSettingsController so that it integrates with media library service and whenever the cell containing this option is tapped , a rescan is launched via media library service
Recently Added Media Group feature for VLC-iOS:
When this feature is turned on , VLC automatically groups newly added files together via Media groups so that user can find it .
This is currently still WIP and required changes to MediaCategoryViewController on VLC-iOS
Conclusions:
I had a great time working on this summer . There were time when I was stuck , and my mentors helped as much as they could. I also got to explore the VLC code for iOS more and now I am more aware of its various components.
Thank you