Browse Source

播放器监听优化

Steven 1 year ago
parent
commit
878a31fac9

+ 3 - 0
KulexiuForStudent/KulexiuForStudent/Common/Base/KSAccompanyWebViewController.m

@@ -1720,7 +1720,10 @@
     }
 }
 
+
 - (void)playerDidError:(kSNewPlayer *)player {
+    [self stopRecordService];
+    [self stopMp3Player]; // 停止播放
     // 播放出现问题
     NSDictionary *postParm = @{@"api" : @"cancelEvaluating",
                                @"content" : @{@"reson":@"播放已停止"}

+ 14 - 0
KulexiuForStudent/KulexiuForStudent/Common/MediaMerge/MusicPlayer/kSNewPlayer.m

@@ -388,6 +388,13 @@
 -(void)playerError:(NSNotification *)notice {
     //移除所有监听
     dispatch_main_sync_safe(^{
+        if ([notice.name isEqualToString:AVAudioSessionRouteChangeNotification]) {
+            NSDictionary *info = notice.userInfo;
+            AVAudioSessionRouteChangeReason routeChangeReason = [[info valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
+            if (routeChangeReason == AVAudioSessionRouteChangeReasonCategoryChange) {
+                return;
+            }
+        }
         if ([self.delegate respondsToSelector:@selector(playerDidError:)]) {
             [self.delegate playerDidError:self];
         }
@@ -400,6 +407,13 @@
     //移除所有监听
     _isPlaying = NO;
     dispatch_main_sync_safe(^{
+        if ([notice.name isEqualToString:AVAudioSessionRouteChangeNotification]) {
+            NSDictionary *info = notice.userInfo;
+            AVAudioSessionRouteChangeReason routeChangeReason = [[info valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
+            if (routeChangeReason == AVAudioSessionRouteChangeReasonCategoryChange) {
+                return;
+            }
+        }
         if ([self.delegate respondsToSelector:@selector(playFinished:)]) {
             [self.delegate playFinished:self];
         }