Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

play sound in swift 5

import AVFoundation
var player: AVAudioPlayer?

func playSound() {
    guard let path = Bundle.main.path(forResource: "beep", ofType:"mp3") else {
        return }
    let url = URL(fileURLWithPath: path)

    do {
        player = try AVAudioPlayer(contentsOf: url)
        player?.play()
        
    } catch let error {
        print(error.localizedDescription)
    }
}
Comment

PREVIOUS NEXT
Code Example
Swift :: swift change navigation bar color 
Swift :: swift has Top Notch 
Swift :: swift remove space from string 
Swift :: Unique device id ios swift 
Swift :: swift ui image on button 
Swift :: access dictionary with index swift 
Swift :: declaration of empty dictionary in swift language 
Swift :: this love taylor swift 
Swift :: how to make extension for optional in swift 
Swift :: uicollectionview detect scroll swift 
Swift :: swift struct field default value 
Swift :: swiftui button style 
Swift :: save Codable in userdefaults and fetch codable from userdefaults ios swift 
Swift :: change button text in swift 
Swift :: swift date plus1 day 
Swift :: swiftui pull to refresh 
Swift :: swift dismiss keyboard on return 
Swift :: string.format swift 
Swift :: struct to json convert in swift 
Swift :: swift get "system" asset image 
Swift :: standard bank swift code 
Swift :: map swift 
Swift :: swift add two arrays 
Swift :: swiftui radio button 
Swift :: xcode execute code after when navigating back to screen 
Swift :: swift make enum inspectable 
Swift :: Swift How to declare an optional in Swift? 
Swift :: Type Constraints Swift 
Swift :: Swift for Loop inside a while Loop 
Swift :: SwiftUI cant tap in spacer of HStack 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =