From 5d3478c7c5ffd9cb23718da7f4e7c2984e17abdd Mon Sep 17 00:00:00 2001 From: JD Buys Date: Tue, 1 Dec 2020 14:36:32 +0200 Subject: [PATCH] Automatically change the volume to default when play is clicked and the volume is muted --- TritonPlayerSDK/Classes/Player/TritonPlayer.m | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/TritonPlayerSDK/Classes/Player/TritonPlayer.m b/TritonPlayerSDK/Classes/Player/TritonPlayer.m index 23c84f4..137cda8 100644 --- a/TritonPlayerSDK/Classes/Player/TritonPlayer.m +++ b/TritonPlayerSDK/Classes/Player/TritonPlayer.m @@ -14,10 +14,11 @@ #import "TDStreamPlayer.h" #import "TDStationPlayer.h" #import "TDMediaPlayer.h" +#import -NSString *const TritonSDKVersion = @"2.6.6"; //TritonSDKVersion +NSString *const TritonSDKVersion = @"2.6.7"; //TritonSDKVersion CGFloat const kDefaultPlayerDebouncing = 0.2f; //Default debouncing for the Play action, in seconds @@ -389,8 +390,24 @@ - (void)play float vol = [[AVAudioSession sharedInstance] outputVolume]; if(vol == 0.0) { - [self failWithError:TDPlayerDeviceMuted andDescription:NSLocalizedString(@"Unmute audio to play", nil)]; - return; + + dispatch_async(dispatch_get_main_queue(), ^{ + // use weakSelf here + + MPVolumeView *volumeView = [[MPVolumeView alloc] init]; + UISlider *volumeViewSlider = nil; + + for (UIView *view in volumeView.subviews) { + if ([view isKindOfClass:[UISlider class]]) { + volumeViewSlider = (UISlider *)view; + break; + } + } + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + volumeViewSlider.value = 0.3f; + }); + }); } if(self.playDebouncingTimer != nil)