Skip to content

Commit

Permalink
Updated some files
Browse files Browse the repository at this point in the history
  • Loading branch information
张柏睿 authored and 张柏睿 committed Nov 11, 2023
1 parent 89dec3f commit 4be871c
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 22 deletions.
Binary file modified .DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions DarockBili Watch App/Extension/CodeExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,19 @@ public class WbiSign: ObservableObject {
}
}
}

postfix operator ++
postfix operator --
extension Int {
@discardableResult
static postfix func ++ (num: inout Int) -> Int {
num += 1
return num
}

@discardableResult
static postfix func -- (num: inout Int) -> Int {
num -= 1
return num
}
}
2 changes: 1 addition & 1 deletion DarockBili Watch App/Others/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ struct SettingsView: View {
}
.navigationTitle("电池")
.onAppear {
batteryLevel = Double(WKInterfaceDevice.current().batteryLevel)
batteryLevel = Double(WKInterfaceDevice.current().batteryLevel * 100.0)
batteryState = WKInterfaceDevice.current().batteryState
debugPrint(batteryLevel)
}
Expand Down
4 changes: 3 additions & 1 deletion DarockBili Watch App/PersonalCenter/DownloadsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct DownloadsView: View {
}
}
})
.sheet(isPresented: $isPlayerPresented, content: {OfflineVideoPlayer()})

.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button(role: .destructive, action: {
try! FileManager.default.removeItem(atPath: vRootPath + metadatas[i]["Path"]!)
Expand All @@ -79,8 +79,10 @@ struct DownloadsView: View {
}
}
}
.sheet(isPresented: $isPlayerPresented, content: {OfflineVideoPlayer()})
.onAppear {
vRootPath = String(AppFileManager(path: "dlds").GetPath("").path)
metadatas.removeAll()
let files = AppFileManager(path: "dlds").GetRoot() ?? [[String: String]]()
for file in files {
debugPrint(file)
Expand Down
15 changes: 15 additions & 0 deletions DarockBili Watch App/UserDynamic/UserDynamicMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ struct UserDynamicMainView: View {
}
}
.navigationTitle("动态")
.navigationBarTitleDisplayMode(.large)
.toolbar {
if #available(watchOS 10, *) {
ToolbarItem(placement: .topBarLeading) {
Button(action: {
lastDynamicID = ""
dynamics.removeAll()
ContinueLoadDynamic()
}, label: {
Image(systemName: "arrow.clockwise")
.foregroundColor(.accentColor)
})
}
}
}
.onAppear {
if !isLoaded {
ContinueLoadDynamic()
Expand Down
3 changes: 2 additions & 1 deletion DarockBili Watch App/Video/VideoDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct VideoDetailView: View {
}, label: {
Image(systemName: "play.fill")
})
.sheet(isPresented: $isVideoPlayerPresented, content: {VideoPlayerView()})

} else {
Button(action: {
mainVerticalTabViewSelection = 3
Expand Down Expand Up @@ -193,6 +193,7 @@ struct VideoDetailView: View {
.bold()
}
}
.sheet(isPresented: $isVideoPlayerPresented, content: {VideoPlayerView()})
.containerBackground(for: .navigation) {
if !isInLowBatteryMode {
ZStack {
Expand Down
83 changes: 64 additions & 19 deletions DarockBili Watch App/Video/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ struct VideoPlayerView: View {
@State var currentTime: Double = 0.0
@State var playerTimer: Timer?
@State var showDanmakus = [[String: String]]()
@State var danmakuWallOffsetX: CGFloat = 0
@State var showedDanmakus: [[(danmaku: Int, offset: Double)]?] = [nil, nil, nil, nil]
@State var tabviewChoseTab = 1
@State var playerRotate = 0.0
@State var player: AVPlayer!
@State var danmakuOffset = 0.0
@State var lastDanmakuOffset = 0.0
@State var lastDanmakuLine = 0
@State var lastDanmakuIndex = 0
var body: some View {
// let asset = AVURLAsset(url: URL(string: VideoDetailView.willPlayVideoLink)!/*, options: ["AVURLAssetHTTPHeaderFieldsKey": [
// "Referer": "https://www.bilibili.com/video/\(VideoDetailView.willPlayVideoBV)",
Expand All @@ -34,8 +39,7 @@ struct VideoPlayerView: View {
// ]]*/, options: [AVURLAssetHTTPUserAgentKey: "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"])
// let item = AVPlayerItem(asset: asset)
// let player = AVPlayer(playerItem: item)
let pExtension = AVExtension(VideoDetailView.willPlayVideoLink)!
let player = pExtension.getPlayer()

ZStack {
TabView(selection: $tabviewChoseTab) {
ScrollView {
Expand All @@ -62,6 +66,7 @@ struct VideoPlayerView: View {
VideoPlayer(player: player)
.rotationEffect(.degrees(playerRotate))
.ignoresSafeArea()
.modifier(zoomable())
.onAppear {
hideDigitalTime(true)
Timer.scheduledTimer(withTimeInterval: 15, repeats: true) { timer in
Expand All @@ -70,14 +75,38 @@ struct VideoPlayerView: View {
// debugPrint(player.currentItem!.status)
// danmakuWallOffsetX = player.currentTime().seconds * 20

debugPrint(pExtension.getCurrentPlayTimeSeconds())
debugPrint(player.currentTime())
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)"
]
AF.request("https://api.bilibili.com/x/click-interface/web/heartbeat", method: .post, parameters: ["bvid": VideoDetailView.willPlayVideoBV, "mid": dedeUserID, "played_time": Int(pExtension.getCurrentPlayTimeSeconds()), "type": 3, "dt": 2, "play_type": 0, "csrf": biliJct], headers: headers).response { response in
AF.request("https://api.bilibili.com/x/click-interface/web/heartbeat", method: .post, parameters: ["bvid": VideoDetailView.willPlayVideoBV, "mid": dedeUserID, "played_time": Int(player.currentTime().seconds), "type": 3, "dt": 2, "play_type": 0, "csrf": biliJct], headers: headers).response { response in
debugPrint(response)
}
}
// Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
// danmakuOffset = -(player.currentTime().seconds * 2.0)
// for i in 0..<showDanmakus.count {
// let appTime = Double(showDanmakus[i]["Appear"]!)!
// var nextLineIndex: Int
// if player.currentTime().seconds - appTime < 1.0 {
// if lastDanmakuLine + 1 > 4 {
// nextLineIndex = 1
// lastDanmakuLine = 0
// } else {
// lastDanmakuLine++
// nextLineIndex = lastDanmakuLine
// }
// } else {
// nextLineIndex = 1
// }
// nextLineIndex--
// if showedDanmakus[nextLineIndex] == nil {
// showedDanmakus[nextLineIndex] = [(i, Double(showDanmakus[i]["Appear"]!)! * 10.0)]
// } else {
// showedDanmakus[nextLineIndex]?.append((i, Double(showDanmakus[i]["Appear"]!)! * 10.0))
// }
// }
// }
}
.onDisappear {
hideDigitalTime(false)
Expand Down Expand Up @@ -121,30 +150,46 @@ struct VideoPlayerView: View {
}
.tabViewStyle(.page)
// if showDanmakus.count != 0 {
// Group {
// ForEach(0...showDanmakus.count - 1, id: \.self) { i in
// if i != 0 {
// let danmakuLast = showDanmakus[i - 1]
// let danmakuThis = showDanmakus[i]
// if (Double(danmakuThis["Appear"]!)! - Double(danmakuLast["Appear"]!)!) <= 3 {
// HStack {
// Text(danmakuThis["Text"]!)
// .offset(x: Double(danmakuThis["Appear"]!)! * 300)
// VStack {
// ZStack {
// LazyVStack {
// if showedDanmakus[0] != nil {
// ZStack {
// ForEach(0..<showedDanmakus[0]!.count, id: \.self) { i in
// Text(showDanmakus[showedDanmakus[0]![i].danmaku]["Text"]!)
// .offset(x: showedDanmakus[0]![i].offset)
// }
// }
// } else {
// VStack {
// Text(danmakuThis["Text"]!)
// .offset(x: Double(danmakuThis["Appear"]!)! * 300)
// }
// if showedDanmakus[1] != nil {
// ZStack {
//
// }
// }
// if showedDanmakus[2] != nil {
// ZStack {
//
// }
// }
// if showedDanmakus[3] != nil {
// ZStack {
//
// }
// }
// }
// }
// Spacer()
// }
// .offset(x: danmakuWallOffsetX)
// .ignoresSafeArea()
// .allowsHitTesting(false)
// .offset(x: danmakuOffset)
// }
}
.ignoresSafeArea()
.onAppear {
let pExtension = AVExtension(VideoDetailView.willPlayVideoLink)!
player = pExtension.getPlayer()

if isPlayerAutoRotating {
WKApplication.shared().isAutorotating = true
}
Expand Down
Binary file not shown.

0 comments on commit 4be871c

Please sign in to comment.