Commit 7458f44b by pidan

礼物和座驾声音播放逻辑

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