Commit 7458f44b by pidan

礼物和座驾声音播放逻辑

parent 7bf1227f
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
@property (atomic, assign) BOOL hasDestroyed; @property (atomic, assign) BOOL hasDestroyed;
@property (nonatomic, assign) BOOL needPlayAudio;
@property (nonatomic, strong) AVPlayer *audioPlayer;
@end @end
@implementation BDAlphaPlayerMetalView @implementation BDAlphaPlayerMetalView
...@@ -63,6 +67,7 @@ ...@@ -63,6 +67,7 @@
NSError *error = nil; NSError *error = nil;
self.renderSuperViewFrame = configuration.renderSuperViewFrame; self.renderSuperViewFrame = configuration.renderSuperViewFrame;
self.model = [BDAlphaPlayerResourceModel resourceModelFromDirectory:configuration.directory orientation:configuration.orientation error:&error]; self.model = [BDAlphaPlayerResourceModel resourceModelFromDirectory:configuration.directory orientation:configuration.orientation error:&error];
self.needPlayAudio = configuration.playAudio;
if (error) { if (error) {
[self didFinishPlayingWithError:error]; [self didFinishPlayingWithError:error];
return; return;
...@@ -103,6 +108,8 @@ ...@@ -103,6 +108,8 @@
- (void)didFinishPlayingWithError:(NSError *)error - (void)didFinishPlayingWithError:(NSError *)error
{ {
[self.audioPlayer pause];
self.audioPlayer = nil;
self.state = BDAlphaPlayerPlayStateStop; self.state = BDAlphaPlayerPlayStateStop;
if (self.delegate && [self.delegate respondsToSelector:@selector(metalView:didFinishPlayingWithError:)]) { if (self.delegate && [self.delegate respondsToSelector:@selector(metalView:didFinishPlayingWithError:)]) {
[self.delegate metalView:self didFinishPlayingWithError:error]; [self.delegate metalView:self didFinishPlayingWithError:error];
...@@ -137,6 +144,13 @@ ...@@ -137,6 +144,13 @@
return; return;
} }
self.state = BDAlphaPlayerPlayStatePlay; self.state = BDAlphaPlayerPlayStatePlay;
if (self.needPlayAudio) {
AVPlayerItem *playItem = [[AVPlayerItem alloc] initWithURL:url];
self.audioPlayer = [AVPlayer playerWithPlayerItem:playItem];
[self.audioPlayer play];
}
__weak __typeof(self) weakSelf = self; __weak __typeof(self) weakSelf = self;
[self renderOutput:output resourceModel:self.model completion:^{ [self renderOutput:output resourceModel:self.model completion:^{
[weakSelf renderCompletion]; [weakSelf renderCompletion];
...@@ -170,6 +184,8 @@ ...@@ -170,6 +184,8 @@
- (void)destroyMTKView - (void)destroyMTKView
{ {
[self.audioPlayer pause];
self.audioPlayer = nil;
self.mtkView.paused = YES; self.mtkView.paused = YES;
[self.mtkView removeFromSuperview]; [self.mtkView removeFromSuperview];
[self.mtkView releaseDrawables]; [self.mtkView releaseDrawables];
......
...@@ -28,6 +28,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -28,6 +28,8 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
@property (nonatomic, assign) CGRect renderSuperViewFrame; @property (nonatomic, assign) CGRect renderSuperViewFrame;
@property (nonatomic, assign) BOOL playAudio;
+ (instancetype)defaultConfiguration; + (instancetype)defaultConfiguration;
@end @end
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#import <YYKit/YYKit.h> #import <YYKit/YYKit.h>
#import <FUSBDAlphaPlayer/BDAlphaPlayer.h> #import <FUSBDAlphaPlayer/BDAlphaPlayer.h>
#import "FUSCacheDataShare.h"
#import "FUSRouter.h"
// 读取WEBP图片最大重试次数 // 读取WEBP图片最大重试次数
#define MAX_RETRY_TIME 3 #define MAX_RETRY_TIME 3
...@@ -100,6 +103,7 @@ ...@@ -100,6 +103,7 @@
configuration.directory = filePath; configuration.directory = filePath;
configuration.renderSuperViewFrame = UIView.fus_screenFrame; configuration.renderSuperViewFrame = UIView.fus_screenFrame;
configuration.orientation = BDAlphaPlayerOrientationPortrait; configuration.orientation = BDAlphaPlayerOrientationPortrait;
configuration.playAudio = [self fus_needPlayAudio];
[self.playView playWithMetalConfiguration:configuration]; [self.playView playWithMetalConfiguration:configuration];
...@@ -112,6 +116,15 @@ ...@@ -112,6 +116,15 @@
} }
} }
- (BOOL)fus_needPlayAudio {
BOOL localEnterRoomCarAudioSwitch = [FUSCacheDataShare shareStore].settingInitDataModel.localEnterRoomCarAudioSwitch == YES;
BOOL isPlayOnSpeaker = [[FUSAudioHelper shareInstance] isPlayOnSpeaker];
return (localEnterRoomCarAudioSwitch
&& (!isPlayOnSpeaker));
}
- (void)fus_endGiftAnimation - (void)fus_endGiftAnimation
{ {
[super fus_endGiftAnimation]; [super fus_endGiftAnimation];
......
...@@ -15,19 +15,10 @@ ...@@ -15,19 +15,10 @@
- (void)fus_playMotorAudioIfNeeded{ - (void)fus_playMotorAudioIfNeeded{
if ([self fus_needPlayAudio]) { if ([self fus_needPlayAudio]) {
NSString *filePath = @"";
if ([NSString isNullWithString:self.mp4Res]) {
if ([[FUSGiftDataCenter sharedCenter] fus_checkGiftResourceExitWithURL:self.audioresource resourceMD5:nil]) { if ([[FUSGiftDataCenter sharedCenter] fus_checkGiftResourceExitWithURL:self.audioresource resourceMD5:nil]) {
filePath = [FUSConfig.sharedInstanced.pathConfigs downloadResourcePath:self.audioresource pathMd5:nil]; NSString *filePath = [FUSConfig.sharedInstanced.pathConfigs downloadResourcePath:self.audioresource pathMd5:nil];
}
} else {
filePath = [FUSConfig.sharedInstanced.pathConfigs downloadResourcePath:self.mp4Res pathMd5:self.mp4Md5];
}
if ([NSString isNullWithString:filePath] == NO) {
[[FUSAudioHelper shareInstance] stop]; [[FUSAudioHelper shareInstance] stop];
[[FUSAudioHelper shareInstance] playWithFilePath:[NSURL URLWithString:filePath] progress:^(NSTimeInterval currentTime) { [[FUSAudioHelper shareInstance] playWithFilePath:[NSURL URLWithString:filePath] progress:^(NSTimeInterval currentTime) {
...@@ -41,6 +32,10 @@ ...@@ -41,6 +32,10 @@
- (BOOL)fus_needPlayAudio { - (BOOL)fus_needPlayAudio {
BOOL audioresourceIsNull = [NSString isNullWithString:self.audioresource]; BOOL audioresourceIsNull = [NSString isNullWithString:self.audioresource];
if (audioresourceIsNull == NO
&& [NSString isNullWithString:self.mp4Res] == NO) {
audioresourceIsNull = YES;
}
BOOL localEnterRoomCarAudioSwitch = [FUSCacheDataShare shareStore].settingInitDataModel.localEnterRoomCarAudioSwitch == YES; BOOL localEnterRoomCarAudioSwitch = [FUSCacheDataShare shareStore].settingInitDataModel.localEnterRoomCarAudioSwitch == YES;
BOOL myselfIsOnMic = [FUSRouter liveRouter].selfOnMicList; BOOL myselfIsOnMic = [FUSRouter liveRouter].selfOnMicList;
BOOL isNotAnchor = ![[FUSRouter liveRouter] isAnchor]; BOOL isNotAnchor = ![[FUSRouter liveRouter] isAnchor];
......
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */ /* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
00E501FF2E0543A800579DB0 /* Exceptions for "NotificationService" folder in "NotificationService" target */ = { 00E501FF2E0543A800579DB0 /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet; isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = ( membershipExceptions = (
"NotificationService-Info.plist", "NotificationService-Info.plist",
...@@ -112,18 +112,7 @@ ...@@ -112,18 +112,7 @@
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */ /* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */ /* Begin PBXFileSystemSynchronizedRootGroup section */
00E501F42E0543A800579DB0 /* NotificationService */ = { 00E501F42E0543A800579DB0 /* NotificationService */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (00E501FF2E0543A800579DB0 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = NotificationService; sourceTree = "<group>"; };
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
00E501FF2E0543A800579DB0 /* Exceptions for "NotificationService" folder in "NotificationService" target */,
);
explicitFileTypes = {
};
explicitFolders = (
);
path = NotificationService;
sourceTree = "<group>";
};
/* End PBXFileSystemSynchronizedRootGroup section */ /* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -675,7 +664,7 @@ ...@@ -675,7 +664,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements; CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 202506230003; CURRENT_PROJECT_VERSION = 202506260001;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6GG26BHUMC; DEVELOPMENT_TEAM = 6GG26BHUMC;
ENABLE_ON_DEMAND_RESOURCES = NO; ENABLE_ON_DEMAND_RESOURCES = NO;
...@@ -943,7 +932,7 @@ ...@@ -943,7 +932,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements; CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 202506230003; CURRENT_PROJECT_VERSION = 202506260001;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6GG26BHUMC; DEVELOPMENT_TEAM = 6GG26BHUMC;
ENABLE_ON_DEMAND_RESOURCES = NO; ENABLE_ON_DEMAND_RESOURCES = NO;
......
...@@ -210,6 +210,7 @@ ...@@ -210,6 +210,7 @@
CGRect renderSuperViewFrame = weakSelf.playView.frame; CGRect renderSuperViewFrame = weakSelf.playView.frame;
configuration.renderSuperViewFrame = renderSuperViewFrame; configuration.renderSuperViewFrame = renderSuperViewFrame;
configuration.orientation = BDAlphaPlayerOrientationPortrait; configuration.orientation = BDAlphaPlayerOrientationPortrait;
configuration.playAudio = [weakSelf.motorModel fus_needPlayAudio];
[weakSelf.playView playWithMetalConfiguration:configuration]; [weakSelf.playView playWithMetalConfiguration:configuration];
...@@ -239,8 +240,9 @@ ...@@ -239,8 +240,9 @@
CGRect keyboardFrame = [FUSKeyboardShowHelper sharedInstance].keyboardFrame; CGRect keyboardFrame = [FUSKeyboardShowHelper sharedInstance].keyboardFrame;
[self fus_restContentYWithKeyboardFrame:keyboardFrame withAnimate:NO]; [self fus_restContentYWithKeyboardFrame:keyboardFrame withAnimate:NO];
} }
if ([NSString isNullWithString:self.motorModel.mp4Res]) {
[self.motorModel fus_playMotorAudioIfNeeded]; [self.motorModel fus_playMotorAudioIfNeeded];
}
_carImageView.alpha = 0; _carImageView.alpha = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment