You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
6.2 KiB
207 lines
6.2 KiB
4 years ago
|
//
|
||
|
// WXYZ_AudioSettingHelper.m
|
||
|
// WXReader
|
||
|
//
|
||
|
// Created by Andrew on 2020/3/18.
|
||
|
// Copyright © 2020 Andrew. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "WXYZ_AudioSettingHelper.h"
|
||
|
#import "WXYZ_Player.h"
|
||
|
#import "WXYZ_GCDTimer.h"
|
||
|
#import <MediaPlayer/MediaPlayer.h>
|
||
|
|
||
|
@interface WXYZ_AudioSettingHelper ()
|
||
|
|
||
|
@property (nonatomic, strong) WXYZ_GCDTimer *countdownTimer;
|
||
|
|
||
|
@property (nonatomic, assign) NSInteger read_timing; // 听书倒计时(有声和ai的计时同步)
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation WXYZ_AudioSettingHelper
|
||
|
|
||
|
implementation_singleton(WXYZ_AudioSettingHelper)
|
||
|
|
||
|
// 倒计时
|
||
|
- (NSInteger)getReadTiming
|
||
|
{
|
||
|
return self.read_timing;
|
||
|
}
|
||
|
|
||
|
- (void)setReadTimingWithIndex:(NSInteger)readTimingIndex
|
||
|
{
|
||
|
_read_timing = readTimingIndex;
|
||
|
}
|
||
|
|
||
|
- (NSArray *)getReadTimingKeys
|
||
|
{
|
||
|
return @[TFLocalizedString(@"不开启"), TFLocalizedString(@"听完本章节"), TFLocalizedString(@"15分钟"), TFLocalizedString(@"30分钟"), TFLocalizedString(@"60分钟"), TFLocalizedString(@"90分钟")];
|
||
|
}
|
||
|
|
||
|
- (NSArray *)getReadTimingValues
|
||
|
{
|
||
|
return @[@"0", @"1", @"900", @"1800", @"3600", @"5400"];
|
||
|
}
|
||
|
|
||
|
// 声音
|
||
|
- (NSString *)getReadVoiceTitleWithProducitionType:(TFProductionType)productionType
|
||
|
{
|
||
|
return [[self getReadVoiceKeysWithProducitionType:productionType] objectAtIndex:[self getReadVoiceWithProducitionType:productionType]];
|
||
|
}
|
||
|
|
||
|
- (NSInteger)getReadVoiceWithProducitionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
return 0;
|
||
|
} else {
|
||
|
NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"xtfei_ai_read_voice"];
|
||
|
return string?[string integerValue] : 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)setReadVoiceWithIndex:(NSInteger)readVoiceIndex producitionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
|
||
|
} else {
|
||
|
[[NSUserDefaults standardUserDefaults] setObject:[TFUtilsHelper formatStringWithInteger:readVoiceIndex] forKey:@"xtfei_ai_read_voice"];
|
||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (NSArray *)getReadVoiceKeysWithProducitionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
return @[];
|
||
|
} else {
|
||
|
return @[TFLocalizedString(@"情感女声"), TFLocalizedString(@"标准女声"), TFLocalizedString(@"标准男声")];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (NSArray *)getReadVoiceValuesWithProducitionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
return @[];
|
||
|
} else {
|
||
|
return @[@"xiaoyan", @"vixq", @"aisbabyxu"];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 语速
|
||
|
- (NSInteger)getReadSpeedWithProducitionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"xtfei_audio_read_speed"];
|
||
|
return string?[string integerValue]:2;
|
||
|
} else {
|
||
|
NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"xtfei_ai_read_speed"];
|
||
|
return string?[string integerValue]:2;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)setReadSpeedWithIndex:(NSInteger)readSpeedIndex producitionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
[[NSUserDefaults standardUserDefaults] setObject:[TFUtilsHelper formatStringWithInteger:readSpeedIndex] forKey:@"xtfei_audio_read_speed"];
|
||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
|
} else {
|
||
|
[[NSUserDefaults standardUserDefaults] setObject:[TFUtilsHelper formatStringWithInteger:readSpeedIndex] forKey:@"xtfei_ai_read_speed"];
|
||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (NSArray *)getReadSpeedKeysWithProducitionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
return @[TFLocalizedString(@"0.5倍"), TFLocalizedString(@"0.75倍"), TFLocalizedString(@"1倍"), TFLocalizedString(@"1.25倍"), TFLocalizedString(@"1.5倍")];
|
||
|
} else {
|
||
|
return @[TFLocalizedString(@"0.5倍"), TFLocalizedString(@"0.75倍"), TFLocalizedString(@"1倍"), TFLocalizedString(@"1.25倍"), TFLocalizedString(@"1.5倍")];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (NSArray *)getReadSpeedValuesWithProducitionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
return @[@"0.5", @"0.80", @"1.0", @"1.25", @"1.5"];
|
||
|
} else {
|
||
|
return @[@"0.5", @"0.80", @"1.0", @"1.25", @"1.5"];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)startTimingFinishBlock:(void(^)(void))finishBlock
|
||
|
{
|
||
|
CGFloat duration = [[[self getReadTimingValues] objectAtIndex:self.read_timing] floatValue];
|
||
|
|
||
|
if (self.read_timing == 0 || self.read_timing == 1) {
|
||
|
[self.countdownTimer stopTimer];
|
||
|
if (finishBlock) {
|
||
|
finishBlock();
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
[self.countdownTimer stopTimer];
|
||
|
[self.countdownTimer startTimerWithTimeDuration:duration];
|
||
|
}
|
||
|
|
||
|
- (void)getCurrentTimingBlock:(void(^)(NSUInteger currentTime))currentTimeBlock finishBlock:(void(^)(void))finishBlock
|
||
|
{
|
||
|
// if ((self.read_timing == 0 || self.read_timing == 1) && ) {
|
||
|
// if (finishBlock) {
|
||
|
// finishBlock();
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
self.countdownTimer.timerRunningBlock = ^(NSUInteger runTimes, CGFloat currentTime) {
|
||
|
if (currentTimeBlock) {
|
||
|
currentTimeBlock([[NSNumber numberWithFloat:currentTime] integerValue]);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
WS(weakSelf)
|
||
|
self.countdownTimer.timerFinishedBlock = ^{
|
||
|
weakSelf.read_timing = 0;
|
||
|
|
||
|
if (finishBlock) {
|
||
|
finishBlock();
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
- (WXYZ_GCDTimer *)countdownTimer
|
||
|
{
|
||
|
if (!_countdownTimer) {
|
||
|
_countdownTimer = [[WXYZ_GCDTimer alloc] initCountdownTimerWithTimeDuration:10 immediatelyCallBack:YES];
|
||
|
}
|
||
|
return _countdownTimer;
|
||
|
}
|
||
|
|
||
|
static BOOL aiPlayPageShow = NO;
|
||
|
static BOOL audioPlayPageShow = NO;
|
||
|
- (void)playPageViewShow:(BOOL)show productionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAi) {
|
||
|
aiPlayPageShow = show;
|
||
|
}
|
||
|
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
audioPlayPageShow = show;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (BOOL)isPlayPageShowingWithProductionType:(TFProductionType)productionType
|
||
|
{
|
||
|
if (productionType == TFProductionTypeAi) {
|
||
|
return aiPlayPageShow;
|
||
|
}
|
||
|
|
||
|
if (productionType == TFProductionTypeAudio) {
|
||
|
return audioPlayPageShow;
|
||
|
}
|
||
|
|
||
|
return NO;
|
||
|
}
|
||
|
|
||
|
@end
|