Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

尝试实现watchOS声音外放及其开关 #401

Merged
merged 7 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"originHash" : "6dafa41a67c3277a909bef0c6c2644adb4ba78f5af49155074ffdd3bc494af0d",
"pins" : [
{
"identity" : "alamofire",
Expand Down Expand Up @@ -33,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/adamzarn/AZVideoPlayer",
"state" : {
"revision" : "75e9e05b87d2bd60d83be4b8db280eb2859a86bc",
"version" : "1.3.0"
"revision" : "a5b2403a35d5768ee4af6c2d27ad9f9a6fb2a789",
"version" : "1.4.0"
}
},
{
"identity" : "cepheus",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Serene-Garden/Cepheus",
"state" : {
"revision" : "5ff00498df1fa89c92af56780d3818c0c4380f6a",
"version" : "2.3.1"
"revision" : "271eba038a2c74c47dc5067d62dd68fc346f6481",
"version" : "2.3.3"
}
},
{
Expand All @@ -52,7 +51,7 @@
"location" : "https://github.com/Darock-Studio/DarockKit",
"state" : {
"branch" : "main",
"revision" : "9a43584cb32e53ae339532a6f49c19c7bc17aa8a"
"revision" : "c36f40dc6174d729836a9fe1cb45bd18573589e5"
}
},
{
Expand Down Expand Up @@ -114,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/SDWebImage/SDWebImage.git",
"state" : {
"revision" : "be0bcd7823ce56629948491f2eaeaa19979514f7",
"version" : "5.19.4"
"revision" : "8a1be70a625683bc04d6903e2935bf23f3c6d609",
"version" : "5.19.7"
}
},
{
Expand Down Expand Up @@ -168,8 +167,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/gonzalezreal/swift-markdown-ui",
"state" : {
"revision" : "9a8119b37e09a770367eeb26e05267c75d854053",
"version" : "2.3.1"
"revision" : "55441810c0f678c78ed7e2ebd46dde89228e02fc",
"version" : "2.4.0"
}
},
{
Expand All @@ -195,8 +194,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/scinfu/SwiftSoup",
"state" : {
"revision" : "028487d4a8a291b2fe1b4392b5425b6172056148",
"version" : "2.7.2"
"revision" : "3c2c7e1e72b8abd96eafbae80323c5c1e5317437",
"version" : "2.7.5"
}
},
{
Expand All @@ -218,5 +217,5 @@
}
}
],
"version" : 3
"version" : 2
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
version = "1.8">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
8 changes: 8 additions & 0 deletions MeowBili/Others/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ struct PlayerSettingsView: View {
@AppStorage("IsShowBottomDanmaku") var isShowBottomDanmaku = true
#if os(watchOS)
@AppStorage("RecordHistoryTime") var recordHistoryTime = "into"
@AppStorage("ExternalSound") var ExternalSound = false
WindowsMEMZ marked this conversation as resolved.
Show resolved Hide resolved
#else
@AppStorage("IsRecordHistory") var isRecordHistory = true
#endif
Expand Down Expand Up @@ -470,6 +471,13 @@ struct PlayerSettingsView: View {
} header: {
Text("弹幕")
}
#if !os(watchOS)
Section {
Toggle("声音外放", isOn: $ExternalSound)
} header: {
Text("声音")
}
#endif
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions MeowBili/Video/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,21 @@ struct VideoPlayerView: View {
if !isFinishedInit {
isFinishedInit = true

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

let asset = AVURLAsset(url: URL(string: videoLink)!, options: ["AVURLAssetHTTPHeaderFieldsKey": ["User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", "Referer": "https://www.bilibili.com"]])
let item = AVPlayerItem(asset: asset)
player = AVPlayer(playerItem: item)
Expand Down