Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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 AVAudioPlayer不';我不能在共享课堂上工作_Ios_Swift_Avaudioplayer - Fatal编程技术网

Ios AVAudioPlayer不';我不能在共享课堂上工作

Ios AVAudioPlayer不';我不能在共享课堂上工作,ios,swift,avaudioplayer,Ios,Swift,Avaudioplayer,我从一个singleton类调用了一个方法,该方法允许播放其他类的声音,但播放机不起作用,我尝试了在处理相同问题的帖子中提到的方法,但对我不起作用,下面是我的代码: import Foundation import AVFoundation import UIKit var soundPlayer = AVAudioPlayer() class MySingleton: NSObject, AVAudioPlayerDelegate { var timer = NSTimer() cl

我从一个singleton类调用了一个方法,该方法允许播放其他类的声音,但播放机不起作用,我尝试了在处理相同问题的帖子中提到的方法,但对我不起作用,下面是我的代码:

import Foundation
import AVFoundation
import UIKit
var soundPlayer = AVAudioPlayer()

class MySingleton: NSObject, AVAudioPlayerDelegate {
var timer = NSTimer()

   class var sharedSingleton: MySingleton {
    struct Static {
        static var onceTocken: dispatch_once_t = 0
        static var instance : MySingleton? = nil
    }
    dispatch_once(&Static.onceTocken) {
        Static.instance = MySingleton()
    }
    return Static.instance!
        }
func callTimer () {
    timer = NSTimer.scheduledTimerWithTimeInterval(0.6, target: self, selector: "repeatedSound", userInfo: nil, repeats: true)
}
func repeatedSound() {

    var repeatedSoundUrl = NSURL(fileURLWithPath:    NSBundle.mainBundle().pathForResource(prayerRepitationList[selectedCellInIndex], ofType: "mp3")!)

    soundPlayer = AVAudioPlayer(contentsOfURL: repeatedSoundUrl, error: nil)
    println("repeated url is \(repeatedSoundUrl)")
    soundPlayer.prepareToPlay()
    soundPlayer.delegate = self
    soundPlayer.play()


}
}
我试过
var播放器:AVAudioPlayer!=无:AVAudioPlayer!=无,但不工作,
如何修复它?

创建计时器时,需要在选择器名称的末尾添加一个冒号“:”,因为该方法指定了一个参数。看起来是这样的:

timer = NSTimer.scheduledTimerWithTimeInterval(0.6, target: self, selector: "repeatedSound:", userInfo: nil, repeats: true)
func repeatedSound(timer: NSTimer) {
  // your other code goes here
}
}

而且,由于计时器调用的方法接收计时器本身的参数,因此必须如下指定:

timer = NSTimer.scheduledTimerWithTimeInterval(0.6, target: self, selector: "repeatedSound:", userInfo: nil, repeats: true)
func repeatedSound(timer: NSTimer) {
  // your other code goes here
}
我没有尝试你的代码,但这应该会有所帮助