Skip to content

Commit

Permalink
Merge pull request #394 from Darock-Studio/feat/player-zoom
Browse files Browse the repository at this point in the history
feat: Added zoom for Video Player
  • Loading branch information
Mark Chan authored Aug 8, 2024
2 parents 521d640 + 6702ee3 commit a049b1f
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 85 deletions.
4 changes: 0 additions & 4 deletions DarockBili.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
8CA3889F2B78B1E300F5F91F /* AZVideoPlayer in Frameworks */ = {isa = PBXBuildFile; productRef = 8CA3889E2B78B1E300F5F91F /* AZVideoPlayer */; };
8CA388A22B78B5D800F5F91F /* BiliFont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 8CA388A02B78B5D800F5F91F /* BiliFont.ttf */; };
8CA388A32B78B5D800F5F91F /* BiliFont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 8CA388A02B78B5D800F5F91F /* BiliFont.ttf */; };
8CA53B032BB963D700D6D692 /* WatchUIDebugView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CA53B022BB963D700D6D692 /* WatchUIDebugView.swift */; };
8CA7CBC32B77AC4A008E587F /* MeowBiliApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CA7CBC22B77AC4A008E587F /* MeowBiliApp.swift */; };
8CA7CBC52B77AC4A008E587F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CA7CBC42B77AC4A008E587F /* ContentView.swift */; };
8CA7CBC72B77AC4C008E587F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8CA7CBC62B77AC4C008E587F /* Assets.xcassets */; };
Expand Down Expand Up @@ -301,7 +300,6 @@
8CA1BA152BD2AFAB009BCDFB /* PrivateSymbols.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrivateSymbols.h; sourceTree = "<group>"; };
8CA370D92B82724400CE0E9E /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
8CA388A02B78B5D800F5F91F /* BiliFont.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = BiliFont.ttf; sourceTree = "<group>"; };
8CA53B022BB963D700D6D692 /* WatchUIDebugView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchUIDebugView.swift; sourceTree = "<group>"; };
8CA7CBC02B77AC4A008E587F /* MeowBili.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MeowBili.app; sourceTree = BUILT_PRODUCTS_DIR; };
8CA7CBC22B77AC4A008E587F /* MeowBiliApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeowBiliApp.swift; sourceTree = "<group>"; };
8CA7CBC42B77AC4A008E587F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -614,7 +612,6 @@
8CA7CCA02B77B2DC008E587F /* LoginView.swift */,
03B2F80E2C45AED7007EB850 /* PhoneFormatterExt.swift */,
8CA7CCA22B77B2F2008E587F /* NoticeView.swift */,
8CA53B022BB963D700D6D692 /* WatchUIDebugView.swift */,
);
path = Others;
sourceTree = "<group>";
Expand Down Expand Up @@ -1232,7 +1229,6 @@
8CBFF1282B861F7F00350E0F /* backtrace.c in Sources */,
8CBFF0EB2B85E55F00350E0F /* FavoriteView.swift in Sources */,
8CBFF0E12B85E55F00350E0F /* UserDynamicMainView.swift in Sources */,
8CA53B032BB963D700D6D692 /* WatchUIDebugView.swift in Sources */,
8C9776092BCECBC3006EDB58 /* Audio.swift in Sources */,
8CBFF0BA2B85E55F00350E0F /* Passthroughs.swift in Sources */,
8CBFF0B92B85E55F00350E0F /* LinkDetectText.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "97df39012f2971497a8865ae77068cc4bbc79ab3288f96b77e2c8898b1305102",
"originHash" : "d28be4d892e241813e1562f4d95d6d86cacedeb289d4f3c74fadfba503aba62d",
"pins" : [
{
"identity" : "alamofire",
Expand Down
15 changes: 0 additions & 15 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2285,9 +2285,6 @@
}
}
},
"DebugVPLD" : {
"shouldTranslate" : false
},
"Dignite" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -5943,12 +5940,6 @@
}
}
},
"TLeft" : {
"shouldTranslate" : false
},
"TRight" : {
"shouldTranslate" : false
},
"Troubleshoot" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -7142,9 +7133,6 @@
}
}
},
"UIDebug" : {
"shouldTranslate" : false
},
"Update.checking" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -9098,9 +9086,6 @@
},
"提交反馈" : {

},
"提交反馈前,请先检查常见问题" : {

},
"搜索" : {
"localizations" : {
Expand Down
5 changes: 0 additions & 5 deletions MeowBili/InMain/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ struct MainView: View {
}, label: {
Text("Home.debug")
})
#if os(watchOS)
NavigationLink(destination: { WatchUIDebugView() }, label: {
Text("UIDebug")
})
#endif
}
if notice != "" {
NavigationLink(destination: { NoticeView() }, label: {
Expand Down
44 changes: 23 additions & 21 deletions MeowBili/MeowBiliApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,36 +167,38 @@ struct DarockBili_Watch_AppApp: App {
var body: some SwiftUI.Scene {
WindowGroup {
if fileLockerPwd != "" {
List {
Section {
Text(fileLockerRetryCount == 0 ? "文件保险箱已启用" : "输入错误")
.font(.title3)
.bold()
.listRowBackground(Color.clear)
}
Section {
TextField("密码", text: $fileLockerInput) {
if fileLockerInput == fileLockerPwd {
fileLockerPwd = ""
} else {
fileLockerInput = ""
fileLockerRetryCount++
}
NavigationStack {
List {
Section {
Text(fileLockerRetryCount == 0 ? "文件保险箱已启用" : "输入错误")
.font(.title3)
.bold()
.listRowBackground(Color.clear)
}
.submitLabel(.continue)
}
if fileLockerRetryCount >= 3 {
Section {
TextField("使用恢复密钥", text: $recoveryCodeInput) {
if recoveryCodeInput == fileLockerRecoverCode {
TextField("密码", text: $fileLockerInput) {
if fileLockerInput == fileLockerPwd {
fileLockerPwd = ""
} else {
recoveryCodeInput = ""
fileLockerInput = ""
fileLockerRetryCount++
}
}
.submitLabel(.continue)
}
if fileLockerRetryCount >= 3 {
Section {
TextField("使用恢复密钥", text: $recoveryCodeInput) {
if recoveryCodeInput == fileLockerRecoverCode {
fileLockerPwd = ""
} else {
recoveryCodeInput = ""
fileLockerRetryCount++
}
}
.submitLabel(.continue)
}
}
}
}
} else {
Expand Down
11 changes: 9 additions & 2 deletions MeowBili/Others/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,15 @@ struct LoginView: View {
]
AF.request("https://passport.bilibili.com/x/passport-login/web/sms/send", method: .post, parameters: BiliSmsCodePost(cid: Int(displayCC)!, tel: Int(accountInput)!, token: loginToken, challenge: challenge, validate: validate, seccode: seccode), headers: headers).response { response in
debugPrint(response)
let json = try! JSON(data: response.data!)
smsLoginToken = json["data"]["captcha_key"].string!
if let json = try? JSON(data: response.data!), let token = json["data"]["captcha_key"].string {
smsLoginToken = token
} else {
#if os(iOS)
AlertKitAPI.present(title: "获取出错", subtitle: "请稍后重试", icon: .error, style: .iOS17AppleMusic, haptic: .error)
#else
tipWithText("获取出错", symbol: "xmark.circle.fill")
#endif
}
}
}
} else {
Expand Down
35 changes: 0 additions & 35 deletions MeowBili/Others/WatchUIDebugView.swift

This file was deleted.

58 changes: 56 additions & 2 deletions MeowBili/Video/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ struct VideoPlayerView: View {
@State var isFullScreen = false
@State var playbackSpeed = 1.0
@State var jumpToInput = ""
@State var playerScale: CGFloat = 1.0
@State var __playerScale = 1.0
@State var playerScaledOffset = CGSizeZero
@State var playerScaledLastOffset = CGSizeZero
@State var cachedPlayerTimeControlStatus = AVPlayer.TimeControlStatus.paused
#endif
@State var currentTime: Double = 0.0
@State var playerTimer: Timer?
Expand Down Expand Up @@ -170,11 +175,52 @@ struct VideoPlayerView: View {
.rotationEffect(.degrees(isFullScreen ? 90 : 0))
.frame(width: isFullScreen ? WKInterfaceDevice.current().screenBounds.height : nil, height: isFullScreen ? WKInterfaceDevice.current().screenBounds.width : nil)
}
if cachedPlayerTimeControlStatus == .paused {
VStack {
ZStack {
Color.accentColor // For tap gesture
.frame(width: 60, height: 40)
.opacity(0.0100000002421438702673861521)
HStack(spacing: 2) {
Image(systemName: "rectangle.portrait.arrowtriangle.2.outward")
.shadow(color: .accentColor, radius: 1)
Text(String(__playerScale))
.shadow(color: .accentColor, radius: 1)
}
.font(.system(size: 14))
}
.onTapGesture {
if __playerScale < 10.0 {
__playerScale += 1.0
playerScale += 1.0
} else {
__playerScale = 1.0
playerScale = 1.0
playerScaledOffset = CGSizeZero
playerScaledLastOffset = CGSizeZero
}
}
Spacer()
}
.ignoresSafeArea()
}
}
.animation(.smooth, value: cachedPlayerTimeControlStatus)
.animation(.smooth, value: playerScale)
.animation(.smooth, value: __playerScale)
.scrollIndicators(.never)
.tag(1)
List {
Section {
SegmentedPicker(selection: $isFullScreen, leftText: "正常", rightText: "全屏")
Button(action: {
isFullScreen.toggle()
tabviewChoseTab = 1
}, label: {
Label(
isFullScreen ? "恢复" : "全屏",
systemImage: isFullScreen ? "arrow.down.right.and.arrow.up.left" : "arrow.down.left.and.arrow.up.right"
)
})
} header: {
Text("画面")
}
Expand Down Expand Up @@ -259,6 +305,14 @@ struct VideoPlayerView: View {
})
}
}
.onReceive(player.publisher(for: \.timeControlStatus)) { status in
if _slowPath(status != cachedPlayerTimeControlStatus) {
if status == .playing {
player.rate = Float(playbackSpeed)
}
cachedPlayerTimeControlStatus = status
}
}
#endif
}
.onAppear {
Expand Down Expand Up @@ -372,7 +426,7 @@ struct VideoPlayerView: View {
@inline(__always)
func UpdateDanmaku() {
AF.request("https://api.bilibili.com/x/v1/dm/list.so?oid=\(videoCID)").response { response in
if let danmakus = String(data: response.data!, encoding: .utf8) {
if let respData = response.data, let danmakus = String(data: respData, encoding: .utf8) {
if danmakus.contains("<d p=\"") {
let danmakuOnly = danmakus.split(separator: "</source>")[1].split(separator: "</i>")[0]
let danmakuSpd = danmakuOnly.split(separator: "</d>")
Expand Down

0 comments on commit a049b1f

Please sign in to comment.