//
//  VxgMediaPlayer.m
//  RNVxgMedia
//
//  Created by zhangkun on 2018/1/23.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "VxgMediaPlayer.h"
#import "RCTRootView.h"

@interface VxgMediaPlayer (){
    MediaPlayer*  players;
    UIView *view;
}
@end

@implementation VxgMediaPlayer
{
    UIView *_reactView;
}


- (instancetype)init
{
    if ((self = [super init])) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationChange:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    }
    return self;
    
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)setUrl:(NSString *)url {
    
    MediaPlayerConfig* config = [[MediaPlayerConfig alloc] init];
    config.connectionUrl = url;
    config.decodingType =1; // HW – 1 //SW – 0
    config.connectionNetworkProtocol = -1;//-1;//
    config.numberOfCPUCores = 2;
    config.synchroEnable = 1;
    config.connectionBufferingTime = 3000;
    config.connectionDetectionTime = 2500;
    config.startPreroll = 0;
    config.aspectRatioMode = 1;
    
    if (players == nil)
    {
        players = [[MediaPlayer alloc] init:CGRectMake( 0, 0, 100, 100 )];
    }
    [self addSubview:[players contentView]];
    self.autoresizesSubviews = TRUE;
    [players Open:config callback:self]; usleep(500000);

}

- (void)layoutSubviews
{
    [super layoutSubviews];
}

- (void)viewDidDisappear:(BOOL)animated {
    NSLog(@"test");
}


- (void)deviceOrientationChange:(NSNotification *)notification
{
    
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    
    switch (orientation) {
        case UIDeviceOrientationPortrait:
        case UIDeviceOrientationPortraitUpsideDown:

            break;
        case UIDeviceOrientationLandscapeLeft:
        case UIDeviceOrientationLandscapeRight:
            
            break;
        default:

            break;
    }
}


@end
