Playing videos in WatchKit app

前端 未结 3 370
执念已碎
执念已碎 2020-12-21 11:52

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?

相关标签:
3条回答
  • 2020-12-21 12:14

    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

    0 讨论(0)
  • 2020-12-21 12:17

    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()
        }
    
    }
    
    0 讨论(0)
  • 2020-12-21 12:18

    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.

    0 讨论(0)
提交回复
热议问题