在 WatchKit 应用中播放视频

Playing videos in WatchKit app

我已经阅读了一些帖子,但没有找到我需要的答案:是否可以在 WatchKit 应用中播放来自 URL 的视频文件或视频?

当前版本的WatchKit (8.2) 不支持视频。可以创建一系列动画图像并在 Watch 上播放它们,但存储和传输成本可能意味着此 "video" 会很短且帧速率较低。据推测,这是他们在其中一个主题演示中用来展示车库门视频的技术。

当前版本的 WatchOS,2.0,允许播放视频,但仅限于本地。请参阅 WKInterfaceMovie class 参考:https://developer.apple.com/library/prerelease/watchos/documentation/WatchKit/Reference/WKInterfaceMovie_class/index.html#//apple_ref/occ/cl/WKInterfaceMovie

我正在分享 objective-c 和 swift 代码块。但之前的评论解释了。视频仅在本地播放。

Objective-C

#import "InterfaceController.h"

@interface InterfaceController()

@end

@implementation InterfaceController

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];

    // Configure interface objects here.
}

- (void)willActivate {
    // This method is called when watch view controller is about to be visible to user
    [super willActivate];
    NSURL* url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mov"];
    [self.myMoviePlayer setMovieURL:url];
}

- (void)didDeactivate {
    // This method is called when watch view controller is no longer visible
    [super didDeactivate];
}

@end

Swift

import WatchKit
import Foundation


class InterfaceController: WKInterfaceController {
    @IBOutlet var myMoviePlayer: WKInterfaceMovie!

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)

        // Configure interface objects here.
    }

    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()

        let url = NSBundle.mainBundle().URLForResource("test", withExtension: "mov")
        self.myMoviePlayer.setMovieURL(url!)
    }

    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        super.didDeactivate()
    }

}