6
6
//
7
7
8
8
import AVKit
9
+ // import NotificationBannerSwift
9
10
10
11
class SpeedChangerPlugin : NSObject , CommonPlayerPlugin {
12
+ private var notifyView : UILabel ?
13
+ private weak var containerView : UIView ?
11
14
private weak var player : AVPlayer ?
12
15
private weak var playerVC : AVPlayerViewController ?
13
16
14
17
@Published private( set) var currentPlaySpeed : PlaySpeed = . default
15
18
19
+ func addViewToPlayerOverlay( container: UIView ) {
20
+ containerView = container
21
+ }
22
+
23
+ private func fadeOutNotifyView( ) {
24
+ UIView . animate ( withDuration: 1.0 , animations: {
25
+ self . notifyView? . alpha = 0.0 // Fade out to invisible
26
+ } ) { _ in
27
+ self . notifyView? . removeFromSuperview ( ) // Optionally remove from superview after fading out
28
+ }
29
+ }
30
+
16
31
func playerDidLoad( playerVC: AVPlayerViewController ) {
17
32
self . playerVC = playerVC
33
+
34
+ currentPlaySpeed = Settings . mediaPlayerSpeed
18
35
}
19
36
20
37
func playerDidChange( player: AVPlayer ) {
@@ -25,6 +42,32 @@ class SpeedChangerPlugin: NSObject, CommonPlayerPlugin {
25
42
playerVC? . selectSpeed ( AVPlaybackSpeed ( rate: currentPlaySpeed. value, localizedName: currentPlaySpeed. name) )
26
43
}
27
44
45
+ func playerDidStart( player: AVPlayer ) {
46
+ if notifyView == nil {
47
+ notifyView = UILabel ( )
48
+ notifyView? . backgroundColor = UIColor . black. withAlphaComponent ( 0.3 )
49
+ notifyView? . textColor = UIColor . white
50
+ containerView? . addSubview ( notifyView!)
51
+ notifyView? . numberOfLines = 0
52
+ notifyView? . layer. cornerRadius = 10 // Set the corner radius
53
+ notifyView? . layer. masksToBounds = true // Enable masks to bounds
54
+ notifyView? . font = UIFont . systemFont ( ofSize: 26 )
55
+ notifyView? . textAlignment = NSTextAlignment . center
56
+ notifyView? . snp. makeConstraints { make in
57
+ // make.bottom.equalToSuperview().inset(20) // 20 points from the bottom
58
+ make. center. equalToSuperview ( ) // Center horizontally
59
+ make. width. equalTo ( 300 ) // Set a width (optional)
60
+ make. height. equalTo ( 60 ) // Set a height (optional)
61
+ }
62
+ }
63
+ notifyView? . isHidden = false
64
+ notifyView? . text = " 播放速度设置为 \( currentPlaySpeed. name) "
65
+
66
+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 ) {
67
+ self . fadeOutNotifyView ( )
68
+ }
69
+ }
70
+
28
71
func addMenuItems( current: inout [ UIMenuElement ] ) -> [ UIMenuElement ] {
29
72
let gearImage = UIImage ( systemName: " gearshape " )
30
73
@@ -43,7 +86,7 @@ class SpeedChangerPlugin: NSObject, CommonPlayerPlugin {
43
86
}
44
87
}
45
88
46
- struct PlaySpeed {
89
+ struct PlaySpeed : Codable {
47
90
var name : String
48
91
var value : Float
49
92
}
0 commit comments