Playing videos in WatchKit app

狂风中的少年 提交于 2019-12-18 09:08:31

问题


I've read some posts, but I don't find the answer I need: is it possible to play a video file or a video from a URL in a WatchKit app?


回答1:


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.




回答2:


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




回答3:


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

}


来源:https://stackoverflow.com/questions/29448350/playing-videos-in-watchkit-app

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