Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从URL拉取时没有来自AVPlayer的音频_Ios_Iphone_Swift_Web_Avplayer - Fatal编程技术网

Ios 从URL拉取时没有来自AVPlayer的音频

Ios 从URL拉取时没有来自AVPlayer的音频,ios,iphone,swift,web,avplayer,Ios,Iphone,Swift,Web,Avplayer,不太清楚我到底做错了什么。第一次与Swift合作。正在尝试播放一个简单的音频文件 // Imports I need import UIKit import AVFoundation class ViewController: UIViewController { var isPlaying = false // variable to control playback selection, used in togglePlayPause var player = AVPl

不太清楚我到底做错了什么。第一次与Swift合作。正在尝试播放一个简单的音频文件

// Imports I need
import UIKit
import AVFoundation

class ViewController: UIViewController {

    var isPlaying = false // variable to control playback selection, used in togglePlayPause

    var player = AVPlayer()

    // A button I have in the center of the View Controller
    @IBOutlet weak var PlayButton: UIButton!

    // A method that toggles playback when that button is hit
    // This SEEMS to work. Everything except audio playing and pausing seems to be working
    // when I debug
    @IBAction func togglePlayPause(sender: AnyObject) {
        if (isPlaying) {
            player.pause()
            PlayButton.setTitle("Play", forState: UIControlState.Normal)    // This works
            print("Pause")                                                  // and this
        } else {
            player.play()
            PlayButton.setTitle("Pause", forState: UIControlState.Normal)   // This works
            print("Play")                                                   // and so does this
        }
        isPlaying = !isPlaying          // I do end up swapping each time this runs. I have
                                        // Breakpoints set up on the first statements of each
                                        // and I hit the opposite one each time I press the button
                                        // Oh, and the text on the button changes accordingly
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        //let url = "http://192.99.131.205:8000/stream.mp3" // This is a Shoutcast stream.
                                                            // Not using it for now
        let url = "http://www.nasa.gov/mp3/640149main_Computers%20are%20in%20Control.mp3"
                                                            // Normal MP3 file from the web
        player = AVPlayer(URL: (NSURL(string: url))!)       // This SHOULD make an AVPlayer
                                                            // that connects to said URL and
        player.play()                                       // this should play it
        isPlaying = true                                    // Keep track
        PlayButton.setTitle("Pause", forState: UIControlState.Normal) // Set button text
        player.volume = 1                                   // FORCE VOLUME FULL JUST IN CASE
    }

    // I honestly could remove this
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
那么,怎么了?嗯,在我的iPhone 5上,运行8.3,至少,我在屏幕的左上角有一个网络加载指示器,但没有音频。它的行为就像它试图播放,但没有声音从我的设备出来

我真的不知道为什么这不起作用。我见过其他的例子,它们就是这样。我可以理解Shoutcast/Icecast流需要更多的工作,但这只是一个奇怪的静态MP3文件

我用我的应用程序编译了AVFoundation和CFNetwork。我想我不需要CFNetwork,但是哦,好吧

我的目标是8.3,运行最新的xcode(昨天刚下载),并在10.11.4的虚拟机上构建。我想更新我的iPhone,但现在不行