If you have any doubts or need help with anything, head over to Gitter and ask it there!
To run the example project, clone the repo, and run pod install
from the Example directory first.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
VersaPlayer is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'VersaPlayer'
VersaPlayer aims to be simple to use but also flexible, to start using VersaPlayer first create a view programatically or via storyboard. Then add this few lines of code to start playing your video.
@IBOutlet weak var playerView: VersaPlayerView!
override func viewDidLoad() {
super.viewDidLoad()
if let url = URL.init(string: "http://rmcdn.2mdn.net/Demo/html5/output.mp4") {
let item = VersaPlayerItem(url: url)
playerView.set(item: item)
}
}
To add controls for your player use the VersaPlayerControls class, which comes packed with outlets to control your player, you can also add as many as you like by making a custom implementation.
VersaPlayerControls class include the following outlets:
Outlet Name | Type | Action |
---|---|---|
playPauseButton | VersaStatefullButton | Toggle playback |
fullscreenButton | VersaStatefullButton | Toggle fullscreen mode |
pipButton | VersaStatefullButton | Toggle PIP mode in supported devices |
rewindButton | VersaStatefullButton | Rewind playback |
forwardButton | VersaStatefullButton | Fast forward playback |
skipForwardButton | VersaStatefullButton | Skip forward the time specified in second at skipSize (found in VersaPlayerControls) |
skipBackwardButton | VersaStatefullButton | Skip backward the time specified in second at skipSize (found in VersaPlayerControls) |
seekbarSlider | VersaSeekbarSlider | Seek through playback |
currentTimeLabel | VersaTimeLabel | Indicate the current time |
totalTimeLabel | VersaTimeLabel | Indicate the total time |
bufferingView | UIView | Shown when player is buffering |
@IBOutlet weak var playerView: VersaPlayerView!
@IBOutlet weak var controls: VersaPlayerControls!
override func viewDidLoad() {
super.viewDidLoad()
playerView.use(controls: controls)
if let url = URL.init(string: "http://rmcdn.2mdn.net/Demo/html5/output.mp4") {
let item = VersaPlayerItem(url: url)
playerView.set(item: item)
}
}
VersaPlayer also brings support for encrypted content, to make use of this funcionality you must implement VersaPlayerDecryptionDelegate and assign it to VersaPlayer's decryptionDelegate property.
To read more about this topic go to:
To make use of different media tracks, such as audio, video, or captioning, use VersaPlayerMediaTracks, found in VersaPlayer class.
to learn more about this properties go to:
Audio tracks are specially helpfull when dealing with different languages, for example for a movie playback.
To select an audio track simply fetch available tracks with VersaPlayer's audioTracks property.
@IBOutlet weak var playerView: VersaPlayer!
...
let tracks: [VersaPlayerMediaTrack] = playerView.player.currentItem?.audioTracks
/// the name of the track
let name = tracks.first?.name
/// the language of the track
let name = tracks.first?.language
/// selecting the first one
tracks.first?.select(for: playerView.player)
Video tracks are most helpfull when dealing with different renditions or different streams per video quality.
To select an video track simply follow the same principles as an audio track.
@IBOutlet weak var playerView: VersaPlayer!
...
let tracks: [VersaPlayerMediaTrack] = playerView.player.currentItem?.videoTracks
/// the name of the track
let name = tracks.first?.name
/// selecting the first one
tracks.first?.select(for: playerView.player)
Caption tracks are almost always helpfull. This can be used from a movie playback all the way to assitive content.
To select an video track simply follow the same principles as video and audio tracks.
@IBOutlet weak var playerView: VersaPlayer!
...
let tracks: [VersaPlayerMediaTrack] = playerView.player.currentItem?.captionTracks
/// the name of the track
let name = tracks.first?.name
/// the language of the track
let name = tracks.first?.language
/// selecting the first one
tracks.first?.select(for: playerView.player)
Caption styling are not usually managed by the user, but when necessary, captionStyling property from VersaPlayer comes in handy.
Explore all the available attributes that can be changed here:
Versa is aimed to be versatile, and that's why it comes with an extensions feature, that lets you customize any aspect of the player by inheriting from VersaPlayerExtension.
This class comes with a player attribute that points to the player instance from which is being used. To add an extension use the add(extension ext:) method found in https://josejuanqm.github.io/Libraries-Documentation/VersaPlayerCore/Classes/VersaPlayer.html.
Here are some extensions for VersaPlayer that may be useful for you.
Full documentation avilable https://josejuanqm.github.io/Libraries-Documentation/VersaPlayerCore/
Jose Quintero - jose.juan.qm@gmail.com
People that make VersaPlayer possible, Thank you!
If you like this project or has been helpful to you, you can buy me a cup of coffe :) Appreciate it!
VersaPlayer is available under the MIT license. See the LICENSE file for more info.