Home SKAction play sound not from begining
Reply: 1

SKAction play sound not from begining

viktor.radovic Published in 2017-12-06 03:49:55Z

I want to play sound not from the beginning of the mp3 file, but from 14s after beginning. I have the following code for sound playing, but i was not successful in finding the solution:

if let textAudio = textAudio {
        let wait = SKAction.wait(forDuration: 0.1)
        let play = SKAction.play()
        if view.scene! == scene02 {
            // play 14s after begining
        textAudio.run(SKAction.sequence([wait, play]))
Alessandro Ornano
Alessandro Ornano Reply to 2017-12-06 09:29:21Z

You can use AVAudioPlayer and the currentTime method as explained here:

import AVFoundation
var textAudio: AVAudioPlayer?
let path = Bundle.main.path(forResource: "example.mp3", ofType:nil)!
let url = URL(fileURLWithPath: path)

do {
    textAudio = try AVAudioPlayer(contentsOf: url)
    textAudio?.currentTime = TimeInterval(14.0)
} catch {
    // couldn't load file :(
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308708 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO