//
//  MKRPlayResourceStatus.m
//  MKRAVPlayer
//
//  Created by yyqxiaoyin on 2019/4/11.
//

#import "MKRPlayResourceStatus.h"

@implementation MKRPlayResourceStatus

- (MKRResourcePlayState)updatePlayState:(NSString *)playStateString{
    if([playStateString isEqualToString:@"STOPPED"] ||
       [playStateString isEqualToString:@"NO_MEDIA_PRESENT"] ){
        return MKRResourcePlayStateStopped;
    }else if([playStateString isEqualToString:@"PLAYING"] ){
        return MKRResourcePlayStatePlaying;
    }else if([playStateString isEqualToString:@"TRANSITIONING"] ){
        return MKRResourcePlayStateBuffering;
    }else if([playStateString isEqualToString:@"PAUSED_PLAYBACK"]){
        return MKRResourcePlayStatePause;
    }else {
        return MKRResourcePlayStateBuffering;
    }
}

- (NSString *)currentTimeFormatString {
    if (self.currentTime == 0){
        return @"00:00";
    }
    int seconds = self.currentTime % 60;
    int minutes = (self.currentTime / 60) % 60;
    int hours = (int)self.currentTime / 3600;
    if (!hours){
        return [NSString stringWithFormat:@"%02d:%02d",minutes,seconds];
    } else{
        return [NSString stringWithFormat:@"%02d:%02d:%02d",hours,minutes,seconds];
    }
}

- (NSString *)totalTimeFormatString {
    if (self.totalTime == 0){
        return @"00:00";
    }
    int seconds = self.totalTime % 60;
    int minutes = (self.totalTime / 60) % 60;
    int hours = (int)self.totalTime / 3600;
    if (!hours){
        return [NSString stringWithFormat:@"%02d:%02d",minutes,seconds];
    } else{
        return [NSString stringWithFormat:@"%02d:%02d:%02d",hours,minutes,seconds];
    }
}

@end
