Wednesday, June 12, 2024
HomeiOS Developmentios - The right way to initialize a AudioPlaybackIntent with parameters?

ios – The right way to initialize a AudioPlaybackIntent with parameters?


I’m attempting to create this

struct PlayAudioIntent: AudioPlaybackIntent {

  personal let fileName:String = ""
  personal let fileExtension:String = ""

  init() {
    do {
      strive AVAudioSession.sharedInstance().setCategory(.playback)
      strive AVAudioSession.sharedInstance().setActive(true)
    } catch {
      print("Didn't arrange audio session class: (error)")
    }
  }

  init(_ fileName:String, _ fileExtension:String) {
    self.fileName = fileName
    self.fileExtension = fileExtension
  }

  func carry out() async throws -> some IntentResult {
    if PlayerModel.shared.isPlaying {
      PlayerModel.shared.pauseAudio()
    } else {
        PlayerModel.shared.setupAudio(fileName, fileExtension)
    }
    return .consequence()
  }
}

when the code arrives at

PlayerModel.shared.setupAudio(fileName, fileExtension)

fileName and fileExtension are empty.

Why is that if the code is executing the init(filename,fileExtension) appropriately in principle saving the variables with the correct values?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments