Playing videos in WatchKit app

跟風遠走 提交于 2019-11-29 15:39:13

The current version of WatchKit (8.2) does not provide support for video. It is possible to create an animated series of images and play them on the Watch, but storage and transmission costs likely mean that this "video" would be short and at a low frame rate. It has been speculated that this is the kind of technique they used to show the garage door video in one of their keynote demos.

The current version of WatchOS, 2.0, Does allow playback of videos but only local. See the WKInterfaceMovie class reference : https://developer.apple.com/library/prerelease/watchos/documentation/WatchKit/Reference/WKInterfaceMovie_class/index.html#//apple_ref/occ/cl/WKInterfaceMovie

I am sharing objective-c and swift code block. But previoues comment explained. Videos play only local.

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

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!