简体   繁体   English

AVAudioPlayerDelegate不调用该方法

[英]AVAudioPlayerDelegate doesn't call the method

Here is the method inside a class: 这是类中的方法:

import UIKIt
import Foundation

class notMoving {
    var drumPlayerObject = drumPlayer()
    var fileManagerObject = fileManager1()
    let drumStrength = 1
    var bassStrength = 1
    var synthStrength = 1
    var indexToPlay: Int = 0

    // here we start the drum player.
    func startToPlay()  {
        fileManagerObject.clearPlayedListDrum(drumStrength, KeyNoteOfInstDrum: "C")
        if let indexToPlay = fileManager1().randomizeTheNextInstrument(fileManager1().drums, Strength: drumStrength, KeyNote: "C")  {
            fileManager1().drums[indexToPlay].4 = true
            self.indexToPlay = indexToPlay
        }
        let instrument = fileManager1().drums[self.indexToPlay].0
        let name = fileManager1().drums[self.indexToPlay].1
        let length = fileManager1().drums[self.indexToPlay].2
        let power = fileManager1().drums[self.indexToPlay].3
        let ifplayed = fileManager1().drums[self.indexToPlay].4
        let tempo = Double(fileManager1().drums[self.indexToPlay].5)
        let bridge: Bool = false
        let extention = fileManagerObject.extentionOfFile
        let loops = fileManager1().drumNumberOfLoops()

        drumPlayerObject.play(instrument, name: name, extentionOfFile: extention, 
            length: length, power: power, ifplayed: ifplayed, tempo: tempo, loops: 
            loops, bridge: bridge)

        fileManager1().clearPlayedListDrum(drumStrength, KeyNoteOfInstDrum: "C")
    }
}

And here is AVAudioPlayerDelegate extension for a drumPlayer class. 这是drumPlayer类的AVAudioPlayerDelegate扩展。

extension drumPlayer : AVAudioPlayerDelegate {
    func audioPlayerDidFinishPlaying(player: AVAudioPlayer!, successfully flag: Bool) {
        println("finished playing \(flag)")
        var notMovingObject = notMoving()
        notMovingObject.startToPlay()
    }

    func audioPlayerDecodeErrorDidOccur(player: AVAudioPlayer!, error: NSError!) {
        println("\(error.localizedDescription)")
    }
}

But audioPlayerDidFinishPlaying doesn't call the startToPlay method after the file is finished.It just only prints "finished playing true" 但是audioPlayerDidFinishPlaying在文件完成后不会调用startToPlay方法。它只会打印“ startToPlay play true”

What I'm doing wrong? 我做错了什么?

您的notMovingObject不会保留在任何地方,因此在程序退出后, audioPlayerDidFinishPlaying()对象将被释放。

I found a solution by creating an instance self.notMovingObject = NotMoving() inside the "func play" of my player. 我通过在播放器的“功能播放”中创建实例self.notMovingObject = NotMoving()找到了解决方案。 So the instance is created only after the player starts. 因此,仅在播放器启动后才创建实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UIDocumentPickerViewController不会调用didPickDocument方法 - UIDocumentPickerViewController doesn't call the didPickDocument method MDCCardCollectionCell不调用didSelect方法-Swift - MDCCardCollectionCell doesn't call didSelect method - swift UIAlertView间歇性不调用委托方法 - UIAlertView Intermittently Doesn't Call Delegate Method ReadRSSI不会调用委托方法 - ReadRSSI doesn't call the delegate method 从类方法调用实例方法不起作用 - Doesn't work to call instance method from class method 符合AVAudioPlayerDelegate - Conforming to AVAudioPlayerDelegate cellForItem(at:IndexPath)方法不使用UICollectionViewCell子类进行调用 - cellForItem(at: IndexPath) method doesn't call with UICollectionViewCell subclass 方法selectRow(at:animated:scrollPosition :)不调用tableView(_:didSelectRowAt :) - The method selectRow(at:animated:scrollPosition:) doesn't call tableView(_:didSelectRowAt:) 调用选择器不会在单独的线程中调用委托方法 - Calling selector doesn't call delegate method in separate thread iOS:Apple Universal Link continueUserActivity方法如果未安装应用程序则不会调用? - iOS: Apple Universal Link continueUserActivity method doesn't call if the app is not installed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM