YHNativeMedia.m 979 Bytes
//
//  YHNativeMedia.m
//  YohoExplorerDemo
//
//  Created by gaoqiang xu on 4/13/15.
//  Copyright (c) 2015 gaoqiang xu. All rights reserved.
//

#import "YHNativeMedia.h"
@import MediaPlayer;

NSString * const YHNative_Media = @"Native_Media";

@implementation YHNativeMedia

- (NSString *)actionName
{
    return YHNative_Media;
}

- (void)playMedia
{
    if (!self.options || !self.options[@"url"]) {
        self.failureCallBack(@"No media url detected!");
        return;
    }
    
    NSString *url = self.options[@"url"];
    MPMoviePlayerViewController *vc = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
    if (!vc) {
        self.failureCallBack(@"Unsupported url!");
        return;
    }
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:vc animated:YES completion:nil];
    
    self.successCallBack(nil, NO);
}

- (NSArray *)availableFunctions
{
    return @[ @"playMedia" ];
}

@end