@@ -22,6 +22,7 @@ class InlineAudioPlayerView: NavigationHeaderView, APDelegate {
2222 private let playOrPause : ImageButton = ImageButton ( )
2323 private let dismiss : ImageButton = ImageButton ( )
2424 private let repeatControl : ImageButton = ImageButton ( )
25+ private let volumeControl : ImageButton = ImageButton ( )
2526 private let progressView : LinearProgressControl = LinearProgressControl ( progressHeight: . borderSize)
2627 private let textView : TextView = TextView ( )
2728 private let containerView : Control
@@ -59,6 +60,7 @@ class InlineAudioPlayerView: NavigationHeaderView, APDelegate {
5960 dismiss. disableActions ( )
6061 repeatControl. disableActions ( )
6162 repeatControl. autohighlight = false
63+ volumeControl. autohighlight = false
6264 textView. isSelectable = false
6365 containerView = Control ( frame: NSMakeRect ( 0 , 0 , 0 , header. height) )
6466
@@ -124,6 +126,7 @@ class InlineAudioPlayerView: NavigationHeaderView, APDelegate {
124126 containerView. addSubview ( repeatControl)
125127 containerView. addSubview ( textView)
126128 containerView. addSubview ( playingSpeed)
129+ containerView. addSubview ( volumeControl)
127130 addSubview ( containerView)
128131 addSubview ( separator)
129132 addSubview ( progressView)
@@ -147,6 +150,25 @@ class InlineAudioPlayerView: NavigationHeaderView, APDelegate {
147150 ( control as! ImageButton ) . set ( image: FastSettings . playingRate == 1.7 ? theme. icons. playingVoice2x : theme. icons. playingVoice1x, for: . Normal)
148151
149152 } , for: . Click)
153+
154+
155+ volumeControl. set ( handler: { [ weak self] control in
156+ if control. popover == nil {
157+ showPopover ( for: control, with: VolumeControllerPopover ( initialValue: CGFloat ( FastSettings . volumeRate) , updatedValue: { updatedVolume in
158+ FastSettings . setVolumeRate ( Float ( updatedVolume) )
159+ self ? . controller? . volume = FastSettings . volumeRate
160+ self ? . updateLocalizationAndTheme ( theme: theme)
161+ } ) , edge: . maxY, inset: NSMakePoint ( - 5 , - 50 ) )
162+ }
163+ } , for: . Hover)
164+
165+ volumeControl. set ( handler: { [ weak self] control in
166+ FastSettings . setVolumeRate ( FastSettings . volumeRate > 0 ? 0 : 1.0 )
167+ if let popover = control. popover? . controller as? VolumeControllerPopover {
168+ popover. value = CGFloat ( FastSettings . volumeRate)
169+ }
170+ self ? . updateLocalizationAndTheme ( theme: theme)
171+ } , for: . Up)
150172 }
151173
152174 private func showAudioPlayerList( ) {
@@ -195,6 +217,8 @@ class InlineAudioPlayerView: NavigationHeaderView, APDelegate {
195217 playOrPause. set ( image: theme. icons. audioPlayerPause, for: . Normal)
196218 dismiss. set ( image: theme. icons. auduiPlayerDismiss, for: . Normal)
197219
220+ volumeControl. set ( image: FastSettings . volumeRate == 0 ? theme. icons. inline_audio_volume_off : theme. icons. inline_audio_volume, for: . Normal)
221+
198222 progressView. fetchingColor = theme. colors. accent. withAlphaComponent ( 0.5 )
199223
200224 if let controller = controller {
@@ -213,7 +237,7 @@ class InlineAudioPlayerView: NavigationHeaderView, APDelegate {
213237 _ = dismiss. sizeToFit ( )
214238 _ = repeatControl. sizeToFit ( )
215239 _ = playingSpeed. sizeToFit ( )
216-
240+ _ = volumeControl . sizeToFit ( )
217241
218242 previous. centerY ( x: 20 )
219243 playOrPause. centerY ( x: previous. frame. maxX + 5 )
@@ -357,17 +381,25 @@ class InlineAudioPlayerView: NavigationHeaderView, APDelegate {
357381
358382 dismiss. centerY ( x: frame. width - 20 - dismiss. frame. width)
359383 repeatControl. centerY ( x: dismiss. frame. minX - 10 - repeatControl. frame. width)
384+
385+
360386 progressView. frame = NSMakeRect ( 0 , frame. height - 6 , frame. width, 6 )
361387 textView. layout? . measure ( width: frame. width - ( next. frame. maxX + dismiss. frame. width + repeatControl. frame. width + ( playingSpeed. isHidden ? 0 : playingSpeed. frame. width + 10 ) ) )
362388 textView. update ( textView. layout)
363389
364- playingSpeed. centerY ( x: dismiss. frame. minX - playingSpeed. frame. width - 20 )
390+ playingSpeed. centerY ( x: dismiss. frame. minX - playingSpeed. frame. width - 10 )
391+
365392
366- let w = ( repeatControl. isHidden ? dismiss. frame. minX : repeatControl. frame. minX) - next. frame. maxX
367-
368393 textView. centerY ( x: next. frame. maxX + 10 )
369394
370395
396+ if repeatControl. isHidden {
397+ volumeControl. centerY ( x: playingSpeed. frame. minX - 10 - volumeControl. frame. width)
398+ } else {
399+ volumeControl. centerY ( x: repeatControl. frame. minX - 10 - volumeControl. frame. width)
400+ }
401+
402+
371403 separator. frame = NSMakeRect ( 0 , frame. height - . borderSize, frame. width, . borderSize)
372404 }
373405
0 commit comments