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 :: UI API called on a background thread 
Swift :: firebase nil value equals 
Swift :: swiftui padding one line 
Swift :: how to swift pie chart quartzcore framework 
Swift :: How to change the backgroundColor of UIDatePicker or UIPicker ? 
Swift :: pushviewcontroller swift autolayout 
Swift :: swift 5 func to increase number every time call 
Swift :: how to find uibutton title text 
Swift :: swift struct field default value 
Swift :: swift play audio stream from url 
Swift :: Return multiple value of different types swift 
Swift :: button in swiftui 
Swift :: set color for uibutton programmatically swift 
Swift :: swiftui tabview 
Swift :: Make a VStack fill the width of the screen in SwiftUI 
Swift :: swift ui enum 
Swift :: porsche 
Swift :: We use the for loop to iterate over the elements of a dictionary. 
Swift :: Swift Swift continue statement with nested loops 
Swift :: swift make condition that you are in sumulator 
Swift :: swiftui popover 
Swift :: Swift Remove an Element from an Array 
Swift :: initialize array with zero in swift 
Swift :: swift extension Array with specific element type 
Swift :: swift resource exceeds maximum size 
Swift :: variable sum in swift 
Swift :: Swift Double 
Swift :: how to screen record swift stackoverflow 
Swift :: command compileswift failed with a nonzero exit code 
Swift :: cherries 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =