If you want that your app support HLS streaming, one of the best options is to use the MobileVLCKit, which is a modular multimedia framework that enables developers to easily add video and audio playback to their iOS applications. But the library does not provide any player but only a view with the video streaming. So, to make it easier to use the MobileVLCKit, I created the VLCKitPlayer, which is a SwiftUI view component that integrates the MobileVLCKit and provides a player for video streaming in your iOS app.
To use VLCKitPlayer in your project, follow these steps:
If you haven't already, install CocoaPods by running the following command in your terminal:
sudo gem install cocoapods
Create a Podfile: Navigate to your project directory in the terminal and create a Podfile by running:
pod init
Add MobileVLCKit as dependency to Your Podfile: Open the Podfile in a text editor and you should add something like this:
target 'YourApp' do
use_frameworks!
platform :ios, '8.4'
pod 'MobileVLCKit', '~>3.3.0'
end
Install the dependencies: Run the following command in your terminal:
pod install
Open the .xcworkspace file: Close your Xcode project and open the .xcworkspace file that was created by CocoaPods.
First of all you need to download and extract the .framework file from the releases section of this repository. Make sure to extract it before proceeding.
Add the VLCKitPlayer.framework to your project:
- From Xcode, open the project navigator and select your project.
- Create a "Frameworks" group in your project if it not exist. (optional)
- Right-click on the "Frameworks" group and select "Add Files to <<YourApp>>".
- Select the VLCKitPlayer.framework file and click "Add".
- Verify that the framework is added to the "Link Binary With Lybraries" section in the "Build Phases" tab of your target.
- On "General" tab of your target, verify if the framework is listed in the "Frameworks, Libraries, and Embedded Content" section.
- If the value for this framework is "Do Not Embed", change it to "Embed & Sign" or "Embed Without Signing" (if you are only testing)
To add the VLCKitPlayer to your SwiftUI view, you can follow the example below:
import SwiftUI
import VLCKitPlayer
struct VLCKitTest: View {
@State private var openFullScreenModal = false
var body: some View {
VStack{
Button(action: {
openFullScreenModal.toggle()
}, label: {
Text("Press Me")
})
}
.fullScreenCover(isPresented: $openFullScreenModal, content: {
VLCKitPlayer(selectedUrl: .constant("YourMp4OrHLSStreamingLink"), present: $openFullScreenModal)
})
}
}
#Preview {
VLCKitTest()
}
To use the VLCKitPlayer, you need to create a SwiftUI view and add the VLCKitPlayer to it. The VLCKitPlayer has two parameters:
- selectedUrl: A binding to a string that represents the URL of the video to be played.
- present: A binding to a boolean that represents if the player should be presented or not.
Here is a preview of the VLCKitPlayer in action:
The player is not configurable yet, but I am working on it (and you can too). If you want to contribute to the project, you can fork the repository and create a pull request with your changes. Feel free to open an issue if you have any questions or suggestions.
This project is not affiliated with the VideoLAN organization. The MobileVLCKit is a project of the VideoLAN organization. This project is just a wrapper around the MobileVLCKit to make it easier to use in SwiftUI.
VLCKitPlayer is available under the MIT license. See the LICENSE file for more info.