0

我正在尝试使用 MPMoviePlayerController 播放音频流。它实际上正在工作,并且非常令人愉悦。但是,我希望用户能够使用滑块控制音量。我进行了很多搜索,大多数人都将 AVPlayer 与 MPVolumeView 一起使用,但我不知道如何使用流。

尽管如此,有没有办法让我使用我现在拥有的代码和设置,但实现一个 UISlider 来控制音量?

这是我所拥有的屏幕截图。播放/暂停按钮有效,用户可以通过点击#来调用,点击链接访问网站。我希望能够使用显示的滑块来控制设备音量。https://41.media.tumblr.com/675b910c01821692ccd952ecd847a55a/tumblr_nlkztlnfIq1r4x08fo1_1280.png

谢谢。

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) {
}
4

1 回答 1

-1

创建一个 UIView 对象并将类更改为 MPVolumeView。

于 2015-06-23T01:07:07.213 回答