Skip to content

Commit

Permalink
fix: Background Playing text and session setup
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsMEMZ committed Oct 12, 2024
1 parent 1e0ff27 commit a245990
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 4 additions & 2 deletions MeowBili/Others/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ struct PlayerSettingsView: View {
@AppStorage("IsShowNormalDanmaku") var isShowNormalDanmaku = true
@AppStorage("IsShowTopDanmaku") var isShowTopDanmaku = true
@AppStorage("IsShowBottomDanmaku") var isShowBottomDanmaku = true
@AppStorage("externalSound") var externalSound: Bool = false
@AppStorage("ExternalSound") var externalSound = false
#if os(watchOS)
@AppStorage("RecordHistoryTime") var recordHistoryTime = "into"
#else
Expand Down Expand Up @@ -473,9 +473,11 @@ struct PlayerSettingsView: View {
}
#if os(watchOS)
Section {
Toggle("声音外放", isOn: $externalSound)
Toggle("允许后台播放", isOn: $externalSound)
} header: {
Text("声音")
} footer: {
Text("若要在后台播放,你需要在播放前连接蓝牙音频设备。")
}
#endif
}
Expand Down
18 changes: 8 additions & 10 deletions MeowBili/Video/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct VideoPlayerView: View {
@AppStorage("IsDanmakuEnabled") var isDanmakuEnabled = true
@AppStorage("IsVideoPlayerGestureEnabled") var isVideoPlayerGestureEnabled = true
@AppStorage("VideoPlayerGestureBehavior") var videoPlayerGestureBehavior = "Play/Pause"
@AppStorage("externalSound") var externalSound: Bool = false
@AppStorage("ExternalSound") var externalSound = false
@State var tabviewChoseTab = 1
@State var isFullScreen = false
@State var playbackSpeed = 1.0
Expand Down Expand Up @@ -324,17 +324,15 @@ struct VideoPlayerView: View {
isFinishedInit = true

#if os(watchOS)
// 根据 externalSound 设置配置 AVAudioSession
let audioSession = AVAudioSession.sharedInstance()
do {
if externalSound {
if externalSound {
// 根据 externalSound 设置配置 AVAudioSession
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(.playback, mode: .default, options: [])
} else {
try audioSession.setCategory(.playAndRecord, mode: .default, options: [])
try audioSession.setActive(true)
} catch {
print("Failed to configure AVAudioSession: \(error)")
}
try audioSession.setActive(true)
} catch {
print("Failed to configure AVAudioSession: \(error)")
}
#endif

Expand Down

0 comments on commit a245990

Please sign in to comment.