65 lines
1.8 KiB
Objective-C
65 lines
1.8 KiB
Objective-C
//
|
|
// WXYZ_ADPangoinVideo.m
|
|
// WXReader
|
|
//
|
|
// Created by LL on 2020/7/29.
|
|
// Copyright © 2020 Andrew. All rights reserved.
|
|
//
|
|
|
|
#import "WXYZ_ADPangolinVideo.h"
|
|
#import <MediaPlayer/MediaPlayer.h>
|
|
#import <AVFoundation/AVFoundation.h>
|
|
|
|
@interface WXYZ_ADPangolinVideo ()
|
|
// 观看视频前的音量大小
|
|
@property (nonatomic ,assign) CGFloat initialVolume;
|
|
@property (nonatomic ,weak) MPVolumeView *volumeView;
|
|
|
|
@end
|
|
|
|
@implementation WXYZ_ADPangolinVideo
|
|
|
|
- (void)createSubviews
|
|
{
|
|
[super createSubviews];
|
|
|
|
self.backgroundColor = [UIColor clearColor];
|
|
}
|
|
|
|
- (void)hide
|
|
{
|
|
[TFPromptManager hideLoading];
|
|
[self removeFromSuperview];
|
|
// 穿山甲广告视频播放结束后会设置成AVAudioSessionCategorySoloAmbient模式导致有声或听书被停止播放
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
|
|
[self restoreVolume];
|
|
});
|
|
}
|
|
|
|
// 恢复音量
|
|
- (void)restoreVolume {
|
|
UISlider *volumeSlider = nil;
|
|
for (UIView *obj in self.volumeView.subviews) {
|
|
if ([obj.class.description isEqualToString:@"MPVolumeSlider"]) {
|
|
volumeSlider = (UISlider *)obj;
|
|
break;
|
|
}
|
|
}
|
|
self.volumeView.showsVolumeSlider = YES;
|
|
[volumeSlider setValue:self.initialVolume animated:NO];
|
|
[volumeSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
|
|
[self.volumeView sizeToFit];
|
|
}
|
|
|
|
- (MPVolumeView *)volumeView {
|
|
if (!_volumeView) {
|
|
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(-100, -100, 40, 40)];
|
|
_volumeView = volumeView;
|
|
[self.window addSubview:volumeView];
|
|
}
|
|
return _volumeView;
|
|
}
|
|
|
|
@end
|