Playing Video on a Page
As of Build 1.07, you can add video to any of your pages / SKScenes. You simply need to have a Color Sprite (SKSpriteNode) named “VideoPlaceholder” in the scene which will act as a placeholder for the video file. The video file will get placed overtop the placeholder.
The three events to play video are listed below…
- PlayVideo – the value should a file in the app’s bundle. Include the extension (for example, .mp4, .m4v, .mov). As of Build 1.131, alternatively, if you exclude the filename, you can use this same event to continue playing a video already loaded (if it was paused). See the demo page named Video for an example, or the image below.
- PlayLoopingVideo – the value should be an MP4 file in the app’s bundle. DO NOT include the file extension in the value. MP4 is hard coded into the code, but if you want to use a different movie type, simply search for “mp4” in Page_Video.swift and change it. This property will automatically loop the SKVideoNode and detect when it is over using an AVPlayer. The only caveat is the video player gets removed briefly between loops, but your VideoPlaceholder sprite could easily remedy this by showing the first frame of the movie (remember, the video player gets added above the VideoPlaceholder in the same exact spot).
- PlayVideoFromURL – the value should be the entire URL of a file hosted on your site. Include the extension (for example, .mp4, .m4v, .mov). As of iOS9 you will need to add a domain exception in the Info.plist file so the app can access this file. In the kit, the Info.plist already has the property App Transport Security Settings > Exception Domains in place (replace “yourserver.com” with your actual server).
- PauseVideo – no value needed. This will pause the video currently playing.
Watch a video about this setup below…
If you stumbled onto this article, it is part of our documentation for the Story Tellers iOS Starter Kit 2. The kit enables you to make children’s book apps and games without writing any code! But it is Swift 2 based and compatible with iOS9 (or higher) and Xcode 7 (or higher), so kit buyers can even extend the functionality to fit their needs further. Some of what we cover in the kit documentation may apply to Xcode in general, so this article could be worth a read even if you aren’t a user. You can purchase Lifetime Updates the kit here, or subscribe Yearly to CartoonSmart and get the latest version, plus access to all of our other kits / tutorials.
We’ve also created an iBook to document the very latest properties in the kit, so be sure to download that as well.