Skip to content

Commit

Permalink
Automatically change the volume to default when play is clicked and t…
Browse files Browse the repository at this point in the history
…he volume is muted
  • Loading branch information
JD Buys committed Dec 1, 2020
1 parent 056e093 commit 5d3478c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions TritonPlayerSDK/Classes/Player/TritonPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
#import "TDStreamPlayer.h"
#import "TDStationPlayer.h"
#import "TDMediaPlayer.h"
#import <MediaPlayer/MediaPlayer.h>



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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5d3478c

Please sign in to comment.