I'm trying to use the MPMoviePlayerController to play an audio stream. It is actually working and it is quite pleasing. However, I would like users to be able to control the volume with a slider. I've searched a lot, and most people are using AVPlayer with MPVolumeView, but I couldn't figure out how to use a stream with that.
Nonetheless, is there a way for me to use the code and setup I have now, but implement a UISlider to control volume?
Here is a screenshot of what I have. The play/pause button works, users can call by tapping the #, visit the website by tapping the link. I would like to be able to use the slider displayed to control device volume. https://41.media.tumblr.com/675b910c01821692ccd952ecd847a55a/tumblr_nlkztlnfIq1r4x08fo1_1280.png
Thanks.
var stream: MPMoviePlayerController!
@IBOutlet weak var requestText: UILabel! = UILabel()
@IBOutlet weak var callNumber: UIButton!
@IBOutlet weak var pauseButton: UIButton!
@IBOutlet weak var playButton: UIButton!
@IBOutlet weak var valume: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
playButton.hidden = true
streamPlayer()
}
func streamPlayer() {
stream = MPMoviePlayerController(contentURL: NSURL(string: "http://peace.str3am.com:6910/")!)
stream.view.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
stream.view.sizeToFit()
stream.movieSourceType = MPMovieSourceType.Streaming
self.view.addSubview(stream.view)
stream.fullscreen = false
stream.prepareToPlay()
stream.play()
stream.controlStyle = MPMovieControlStyle.Embedded
}
@IBAction func pausePressed(sender: UIButton) {
stream.stop()
pauseButton.hidden = true
playButton.hidden = false
}
@IBAction func playPressed(sender: UIButton) {
stream.play()
pauseButton.hidden = false
playButton.hidden = true
}
@IBAction func phoneRequest(sender: UIButton) {
pauseButton.hidden = true
playButton.hidden = false
stream.stop()
requestText.text = "Calling..."
if let url = NSURL(string: "tel://\(6072741059)"){
UIApplication.sharedApplication().openURL(url)
}
}
@IBAction func visitWeb(sender: UIButton) {
if let url = NSURL(string: "http://vicradio.org/"){
UIApplication.sharedApplication().openURL(url)
}
}
@IBAction func sliderVal(sender: UISlider) {
}