在Apple Watch WatchKit上显示视频

时间:2015-06-04 06:58:50

标签: watchkit apple-watch

任何人都知道如何在Apple Watch上显示.mp4电影吗?

我已经检查过来自苹果的其他网址this page

但是没有得到关于在苹果手表上显示视频的任何线索。

那么,是否可以在苹果手表上显示mp4视频,或者无法显示。

3 个答案:

答案 0 :(得分:0)

目前的WatchKit SDK不支持视频播放。您最接近的是使用视频中的帧创建动画图像并将其传输到Watch。除了慢速传输,帧速率也会非常低,而且你没有音频。无处接近理想。

答案 1 :(得分:0)

我尝试过使用openParentApplication:reply:从扩展名调用应用程序调用:handleWatchKitExtensionRequest:reply:由ios应用程序中的app delegate调用的委托(响应扩展名)。

这两个功能允许您在应用和手表扩展之间来回传递字典。

我调用openParentApplication:reply:它允许我传递一个字典,然后传递应用程序:handleWatchKitExtensionRequest:reply:自动调用,当它完成后,它会调用openParentApplication的回调:reply:

我基本上创建了一个循环。

我能够将nsstrings和nsnumbers(一个计数器)传递回app delegate的扩展名。循环在模拟器中执行得相当快(但是根据我对文档的理解,我不会看到它在模拟器外侧慢得多,因为扩展代码也驻留在iphone上)。

无论如何,一旦我尝试在这个等式中添加一个uiimage(回调中的字典),整个字典在扩展回调中都会被收到为nil(不再是nsnumber,也没有nsstring)。

似乎操作系统可能会故意阻止像这样的视频尝试(手动图像框架)。

如果其他人有任何想法,我很乐意听到他们的意见。 我还没有试过'切换'。

答案 2 :(得分:0)

As mentioned in jessica's answer,您可以使用WKInterfaceMovie对象在单独的全屏模式视图中播放视频。

watchOS 3添加了一个WKInterfaceInlineMovie对象,可以在当前界面中播放电影。

Apple更新了他们的WatchKit Catalog sample code以包含一个MovieDetailController示例,演示如何播放内联电影代替海报图片:

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
    }
}
相关问题