Playing videos in WatchKit app

前端 未结 3 369
执念已碎
执念已碎 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: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()
        }
    
    }
    

提交回复
热议问题