在WatchKit应用程序中播放视频

时间:2015-04-04 15:49:18

标签: ios file url video watchkit

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

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:0)

我正在分享objective-c和swift代码块。但是前面的评论解释说。视频只播放本地。

<强>目标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

<强>夫特

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()
    }

}