How to make a button in Xcode that globally stops AVAudioPlayer?

Adem

I'm trying to make a tableviewcell stop all sounds in the app when it is clicked. I know how to stop sounds with soundEffect.stop() soundEffect.currentTime = 0, but I don't know how to apply this to a cell and this doesn't work if the StopSound button is on another viewController with a different class. How do I make a function that globally stops AVAudioPlayer and apply that to a cell?

Morgachev

The problem is that the player is not alone. Try this.

To stop AVAudioPlayer on another ViewController you may use NotificationCenter.

Example...

First time, add function at VC, where you need to stop AVAudioPlayer.

@objc func stopAVonThisVC() {
    AVaudioPlayer.stop()
}

Second, add NotificationCenter observer at this VC, and after just post on tap button.

    // At VC, where you need to stop AVAudioPlayer.
NotificationCenter.default.addObserver(self, selector:
    #selector(stopAVonThisVC), name: NSNotification.Name("Stop at VC1"), object: nil)
    // At VC2
NotificationCenter.default.post(name: NSNotification.Name("Stop at VC1"), object: nil)

Sorry for poor english.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to call a method when AVAudioPlayer stops playing

How to make a button which stops my thread with a while

How to make a button or label above a CALayer in Xcode?

How to make a phone call with the press of a button - XCode

How to make Cmake globally available

How to make a function for counting no of stops

How can I make the button text a specific color Xcode Swift

How can I make a custom button in Xcode using swift?

How can I make a Back button on a Tabbed View App in Xcode

How to make a variable globally accessible in Prestashop

How to make globally callable python program?

How to make a class accessible globally in a Laravel application?

How to make jQuery constructor properties globally visible

How to make variables within a function available globally

How to make dotnet globally accessible in windows powershell?

Button to make dynamic alert appear works only once then stops

How to make the game stops if object hit the other?

How to make RecyclerView stops recycling defined positions?

How to set bar button item background image globally in iOS 13

how to change the button text color on AlertDialog globally using style?

How to change android button text color globally in theme

How to change the styling of the dotted line around focused button globally in wpf?

Stop AVAudioplayer from single button

How to make custom settings data available globally in Yii 2?

How do I make the dataframe within an R function globally accessible?

How do you make AngularJS built-in services available globally?

How make ngIf directive globally visible in all project?

node.js: how to make asynchronous data available globally

How to make new data type globally accessible in Swift?

TOP Ranking

HotTag

Archive