iOS D
iOS D

Reputation: 19

Display Video on Apple Watch WatchKit

Can any one know how to display .mp4 movie on Apple Watch ?

I have checked with other urls from apple as well this page

But not getting any clue about to display video on apple watch.

So, is it possible to display mp4 video on apple watch or it is not possible.

Upvotes: 1

Views: 1766

Answers (4)

user4151918
user4151918

Reputation:

As mentioned in jessica's answer, you can play a video in a separate full-screen modal view, using WKInterfaceMovie object.

watchOS 3 adds a WKInterfaceInlineMovie object which plays a movie in place within the current interface.

Apple has updated their WatchKit Catalog sample code to include a MovieDetailController example demonstrating how to play an inline movie in place of a poster image:

class MovieDetailController: WKInterfaceController {
    @IBOutlet var movie :WKInterfaceMovie!
    @IBOutlet var inlineMovie :WKInterfaceInlineMovie!
    @IBOutlet var tapGestureRecognizer :WKTapGestureRecognizer!
    var playingInlineMovie :Bool = false

    override func awake(withContext context: AnyObject?) {
        super.awake(withContext: context)

        // Obtain a URL pointing to the movie to play.
        let movieURL = Bundle.main().urlForResource("Ski1", withExtension: "m4v")

        // Setup the `movie` interface object with the URL to play.
        movie.setMovieURL(movieURL!)

        // Provide a poster image to be displayed in the movie interface object prior to playback.
        movie.setPosterImage(WKImage(imageName: "Ski1"))

        // Setup the `inlineMovie` interface object with the URL to play.
        inlineMovie.setMovieURL(movieURL!)

        // Provide a poster image to be displayed in the inlineMovie interface object prior to playback.
        inlineMovie.setPosterImage(WKImage (imageName: "Ski1"))

        // Movie playback starts
        playingInlineMovie = false
    }

    @IBAction func inlineMovieTapped(sender : AnyObject) {
        if playingInlineMovie == false {
            inlineMovie.play()
        } else {
            inlineMovie.pause()
        }

        playingInlineMovie = !playingInlineMovie
    }
}

Upvotes: 2

jessica
jessica

Reputation: 11

Video is possible with WKInterfaceMovie in watchOS 2

"A WKInterfaceMovie object lets you play back video and audio content directly from your interface. For audio and video assets played directly from your app, keep your clips relatively short. Short clips consume less space on disk, use less power, and take less time to download." https://developer.apple.com/library/prerelease/watchos/documentation/WatchKit/Reference/WKInterfaceMovie_class/index.html

Upvotes: 0

greenhouse
greenhouse

Reputation: 1281

i have tried using openParentApplication:reply: called from the extension in conjunction with application:handleWatchKitExtensionRequest:reply: delegate invoked by the app delegate in the ios app (to respond to the extension).

these two functions allow you to pass dictionaries back and forth between the app and the watch extension.

i call openParentApplication:reply: which allows me to pass a dictionary and then application:handleWatchKitExtensionRequest:reply: is automatically invoked, and when that's finished it invokes a callback from openParentApplication:reply:

i basically create a loop out of this.

i am able to get nsstrings and nsnumbers (a counter) passed back to the extension from the app delegate. the loop executes pretty quickly in the simulator (however i don't see it being much slower out side of the simulator, as the extension code resides on the iphone as well, according to my understanding of the documentation).

anyway, once i try to add a uiimage to this equation (to the dictionary in the callback), the entire dictionary gets received as nil in the extension callback (no nsnumber anymore, and no nsstring).

it seems perhaps the os is intentionally blocking video attempts like this (manually image framing).

if anyone else has any ideas, i would love to hear them. i haven't tried 'handoffs' yet.

Upvotes: 0

Mike Swanson
Mike Swanson

Reputation: 3347

The current WatchKit SDK does not support video playback. The closest you'd get is if you created an animated image using the frames in your video and transferred it to the Watch. In addition to a slow transfer, the frame rate would be pretty low, and you'd have no audio. Nowhere close to ideal.

Upvotes: 1

Related Questions