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
+ let filteredItems = PlaySpeed . blDefaults. filter { $0. value == Settings . mediaPlayerSpeed. speed }
35
+ if !filteredItems. isEmpty {
36
+ currentPlaySpeed = filteredItems [ 0 ]
37
+ }
18
38
}
19
39
20
40
func playerDidChange( player: AVPlayer ) {
@@ -25,6 +45,32 @@ class SpeedChangerPlugin: NSObject, CommonPlayerPlugin {
25
45
playerVC? . selectSpeed ( AVPlaybackSpeed ( rate: currentPlaySpeed. value, localizedName: currentPlaySpeed. name) )
26
46
}
27
47
48
+ func playerDidStart( player: AVPlayer ) {
49
+ if notifyView == nil {
50
+ notifyView = UILabel ( )
51
+ notifyView? . backgroundColor = UIColor . black. withAlphaComponent ( 0.3 )
52
+ notifyView? . textColor = UIColor . white
53
+ containerView? . addSubview ( notifyView!)
54
+ notifyView? . numberOfLines = 0
55
+ notifyView? . layer. cornerRadius = 10 // Set the corner radius
56
+ notifyView? . layer. masksToBounds = true // Enable masks to bounds
57
+ notifyView? . font = UIFont . systemFont ( ofSize: 26 )
58
+ notifyView? . textAlignment = NSTextAlignment . center
59
+ notifyView? . snp. makeConstraints { make in
60
+ // make.bottom.equalToSuperview().inset(20) // 20 points from the bottom
61
+ make. center. equalToSuperview ( ) // Center horizontally
62
+ make. width. equalTo ( 300 ) // Set a width (optional)
63
+ make. height. equalTo ( 60 ) // Set a height (optional)
64
+ }
65
+ }
66
+ notifyView? . isHidden = false
67
+ notifyView? . text = " 播放速度设置为 \( currentPlaySpeed. name) "
68
+
69
+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 ) {
70
+ self . fadeOutNotifyView ( )
71
+ }
72
+ }
73
+
28
74
func addMenuItems( current: inout [ UIMenuElement ] ) -> [ UIMenuElement ] {
29
75
let gearImage = UIImage ( systemName: " gearshape " )
30
76
0 commit comments