From 4e644d01384064b87bd3340a7c43cf09698666b7 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 29 Oct 2025 11:52:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DiOS=E7=9A=84=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=20=E6=81=A2=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_api/MusicSystemFunctionHandler.swift | 10 ++++---- .../Sources/music_service/MusicService.swift | 25 ------------------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/MusicSystemFunctionHandler.swift b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/MusicSystemFunctionHandler.swift index 9d65f4fdd..a32b923e5 100644 --- a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/MusicSystemFunctionHandler.swift +++ b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/MusicSystemFunctionHandler.swift @@ -30,9 +30,9 @@ class MusicSystemFunctionHandler { ) // 注册媒体控制函数 - registerMediaPlayFunction(client: client) + registerMediaResumeFunction(client: client) registerMediaPauseFunction(client: client) - registerMediaCloseFunction(client: client) +// registerMediaCloseFunction(client: client) registerMediaPreviousFunction(client: client) registerMediaNextFunction(client: client) } @@ -99,7 +99,7 @@ private class MusicSearchHandler: FunctionHandler { } /// 注册媒体播放函数 -private func registerMediaPlayFunction(client: MCPClient) { +private func registerMediaResumeFunction(client: MCPClient) { let parameters: [String: Any] = [ "type": "object", "properties": [:], @@ -195,14 +195,14 @@ private class MediaPlayHandler: FunctionHandler { /// 媒体暂停处理器 private class MediaPauseHandler: FunctionHandler { func handle(arguments: [String: Any]) async throws -> String { - NotificationCenter.default.post(name: NSNotification.Name("MediaStop"), object: nil) + NotificationCenter.default.post(name: NSNotification.Name("MediaPause"), object: nil) return "{\"broadcast\": false,\"result\": \"已停止音乐播放\"}" } } /// 媒体暂停处理器 private class MediaCloseHandler: FunctionHandler { func handle(arguments: [String: Any]) async throws -> String { - NotificationCenter.default.post(name: NSNotification.Name("MediaPause"), object: nil) + NotificationCenter.default.post(name: NSNotification.Name("MediaStop"), object: nil) return "{\"broadcast\": false,\"result\": \"已暂停音乐播放\"}" } } diff --git a/local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift b/local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift index 226cf7d1f..88c258c8c 100644 --- a/local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift +++ b/local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift @@ -1052,28 +1052,3 @@ public class MusicService: NSObject { ) } } - -// 实现 CXCallObserverDelegate -//extension MusicService: CXCallObserverDelegate { -// public func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) { -// // 检测通话开始(来电被接听 或 呼出被接通) -// if call.hasConnected && !call.hasEnded { -// // 记录播放状态(避免重复标记,仅在通话刚连接时标记) -// if !call.hasEnded { // 确保是通话开始而非结束 -// self.interruptedDuringPlayback = isPlaying -// if isPlaying { -// print("检测到通话开始,暂停音乐") -// pause() -// } -// } -// } -// // 通话结束且当前无其他活跃通话 -// if call.hasEnded && call.hasConnected { -// // 确保播放器处于暂停状态再恢复 -// if self.interruptedDuringPlayback { -// print("检测到通话结束,恢复音乐") -// self.resume() -// } -// } -// } -//}