Skip to content

Commit

Permalink
volume slider fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Halpin committed Oct 16, 2023
1 parent b9bb694 commit 0892194
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 9 additions & 3 deletions HalpoPlayer/Views/NowPlayingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,15 @@ struct NowPlayingView: View {

Spacer()
}
VolumeSlider()
.frame(height: 40)
.padding(.horizontal)
HStack {
Image(systemName: "speaker")
.foregroundStyle(.gray)
VolumeSlider()
Image(systemName: "speaker.wave.3")
.foregroundStyle(.gray)
}
.frame(height: 40)
.padding(.horizontal)
HStack {
Spacer()
AirPlayView.shared
Expand Down
22 changes: 19 additions & 3 deletions HalpoPlayer/Views/VolumeSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,30 @@ import MediaPlayer
import UIKit

struct VolumeSlider: UIViewRepresentable {
func makeUIView(context: Context) -> MPVolumeView {
let slider = MPVolumeView(frame: .zero)

class SystemVolumeView: MPVolumeView {
override func volumeSliderRect(forBounds bounds: CGRect) -> CGRect {
var newBounds = super.volumeSliderRect(forBounds: bounds)
newBounds.origin.y = bounds.origin.y
newBounds.size.height = bounds.size.height
return newBounds
}
override func volumeThumbRect(forBounds bounds: CGRect, volumeSliderRect rect: CGRect, value: Float) -> CGRect {
var newBounds = super.volumeThumbRect(forBounds: bounds, volumeSliderRect: rect, value: value)
newBounds.origin.y = bounds.origin.y
newBounds.size.height = bounds.size.height
return newBounds
}
}

func makeUIView(context: Context) -> SystemVolumeView {
let slider = SystemVolumeView(frame: .zero)
for v in slider.subviews where v is UISlider {
let slider = v as? UISlider
slider?.thumbTintColor = .clear
}
return slider
}

func updateUIView(_ view: MPVolumeView, context: Context) {}
func updateUIView(_ view: SystemVolumeView, context: Context) {}
}

0 comments on commit 0892194

Please sign in to comment.