Просмотр исходного кода

本地音频文件播放修复

桂欢 1 год назад
Родитель
Сommit
5ca373f179

+ 2 - 0
SLAiELTS/SLAiELTS/AppMarcos/YMConstMacro.h

@@ -91,6 +91,8 @@
 ///
 #define StrongWeakSelf   typeof(wkSelf) __strong stSelf=wkSelf;
 
+#define YMPath_DOCUMENT     [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
+
 
 #define SLBgColor      SLColor(@"#F2F3F7")
 

+ 4 - 1
SLAiELTS/SLAiELTS/ViewControllers/RoleLabelVC/Models/SLNuisdkPlay.m

@@ -131,7 +131,10 @@ static BOOL loop_flag = NO;
 
 - (void)playSendVoice:(MessageModel *)model {
     [self stopNuisdkPlay];
-    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:model.voicePath] error:nil];
+    NSError *error;
+    NSString *urlStr = [model.voicePath componentsSeparatedByString:@"Documents"].lastObject;
+    NSString *voicePath = [YMPath_DOCUMENT stringByAppendingFormat:@"%@", urlStr];
+    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:voicePath] error:&error];
     self.audioPlayer.delegate = self;
     [self.audioPlayer play];
 }