Skip to main content
Version: iOS SDK v1.0.11

Players Manager

For the cases when single view players don't cover all your needs, we created VKPlayersManager component which provides more flexibility of playback experience and handles all video preparations for you.

VKPlayersManager

This component takes VKPlaylist as an input and prepares individual VKPlayerViewController for every video in the playlist. So if you have a use case like a video feed, where you need to present every video individually, this component is the best option. It will take over the preloading, preparation and caching of videos, and you will only need to request a prepared player for a specific video and present it the way you need.

Usage example

Let's take a look at a simple example of using the player manager. Assuming we have a list of video ids we want to play.

// Create custom playlist with list of videos
let playlist = VKCustomPlaylist(videoIds: [
"47d3a28f-09a1-4e7e-bf72-188969c9489d",
"70a7e264-2109-4e8b-b4f9-7951d6dbe9a8",
"6078d65a-37f0-4242-ab24-7c426309bbfb",
"189693c-bc9d-4f42-aa09-c61c5ba252bc",
"665e6994-44c0-4aa2-852a-366d218527a6"
])
// Create players manager
let manager = VKPlayersManager()

// Set the playlist to manager
manager.setPlaylist(playlist)

Once the manager has a playlist, it will take over the preparation of the playlist videos. So now you only need to request prepared player for desired video. You can request player by video index in playlist:

manager.getPlayerFor(index: 0) { player, error  in
if let player = player {
// Insert prepared player to needed place in your interface
}
}

Or by video id:

manager.getPlayerFor(videoId: "47d3a28f-09a1-4e7e-bf72-188969c9489d") { player, error  in
if let player = player {
// Insert prepared player to your interface
}
}

Important note: you should always keep updated current playlist index for the manager. By having actual current playlist index, players manager can re-prioritize preloading order of playlist videos to your actual need. So you will always have prepared player for next required video. E.g. you were watching the first playlist video in your app and then moved to the third video, you should do:

manager.setPlaylistIndex(2)

So now manager can re-adjust preloading order and then you will move to the forth video, it will be ready for playback. Players manager also has smart adjustment algorithm, it analyzes the way you change playlist index and may accelerate preloading from one or another direction.

Another important moment is that you should always release player as soon as it's not visible and you don't need it anymore.

manager.releasePlayerFor(id: "47d3a28f-09a1-4e7e-bf72-188969c9489d")

This way manager can use just a few players for playback of infinite number of videos and keep memory consumption minimal.

Example application

Here you can find example app with implementation of infinite video feed using VKPlayersManager.