Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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 在Swift中使用AVPlayer重新启动音频文件时出错_Ios_Swift_Avaudioplayer - Fatal编程技术网

Ios 在Swift中使用AVPlayer重新启动音频文件时出错

Ios 在Swift中使用AVPlayer重新启动音频文件时出错,ios,swift,avaudioplayer,Ios,Swift,Avaudioplayer,在Swift 3中,我想使用AVPlayer()播放音频,该播放器具有播放、暂停和重新启动音频的功能 根据教程,此视图控制器中的代码成功地播放,暂停,但在重新启动时导致错误: import UIKit //4 - import AVKit import AVFoundation class Music1ViewController: UIViewController { //5 - var songPlayer = AVAudioPlayer() var player

在Swift 3中,我想使用
AVPlayer()
播放音频,该播放器具有播放、暂停和重新启动音频的功能

根据教程,此视图控制器中的代码成功地播放暂停,但在重新启动时导致错误:

import UIKit
//4 -
import AVKit
import AVFoundation

class Music1ViewController: UIViewController {

    //5 -
    var songPlayer = AVAudioPlayer()
    var player = AVPlayer()
    //15 -
    var hasBeenPaused = false


    @IBAction func play(_ sender: Any) {

        let playerItem = AVPlayerItem(url: URL(string: "https://s3.amazonaws.com/kargopolov/kukushka.mp3")!)
        player = AVPlayer(playerItem: playerItem)
        player.play()
    }

    @IBAction func pause(_ sender: Any) {

        player.pause()

    }

    @IBAction func restart(_ sender: Any) {
        //17 -
        if player.isPlaying || hasBeenPaused {
            player.stop()
            player.currentTime = 0

            player.play()
        } else  {
            player.play()
        }
    }
这导致一个错误:
类型为“AVPlayer”的值没有成员“isPlaying”

查看文档,我看不出我遗漏了什么,因为我相信我已经为
player
定义了变量,
AVPlayer
似乎接受状态作为其模型的一部分


是否有更好的方法告诉
AVPlayer
从一个值开始(在本例中,是音频文件的0秒标记)

AVPlayer确实没有“isplay”或“playing”属性。我认为您应该使用'rate==1'或'timeControlStatus==AvPlayerItemControlStatusPlaying'(iOS10或更高版本)来检查现在是否正在播放。

为什么不查阅有关iPlaying的文档?