Play .opus files in Swift 3-4

0

Good, my question is how I could play an .opus file from my application in swift, the file is remote on a server and I would have to take that file and play it in the application, how could I do it? since I've tried it in every way and there's no way it works

func escucharCancion(){
    let url = URL(string: "http://solivellaluisalberto.000webhostapp.com/prueba.opus")

    do {
        let audioData = try Data(contentsOf: url!)
        try audioPlayer = AVAudioPlayer(data: audioData)
        audioPlayer.prepareToPlay()
    } catch {

    }
}

The problem is that being .opus does not load the song, but when it's .mp3 it works perfectly.

I have not done debug, but I know that the error is when trying to pass to Data the .opus file, when it is .mp3 if it is passed to Data correctly from the URL, but with the .opus does not work

    
asked by Luis Alberto Murcia Solivella 24.10.2017 в 13:22
source

1 answer

1

The MobileVLCKit library comes in handy in this case, it is in Objective - C but you should not have problems when using the methods.

MobileVLCKit Documentation

Download Link

First set up your project to work the classes obj-c in your swift project 3.

1.- Create VLCMedia with the content of your URL:

var instanciaVLCMedia: VLCMedia = VLCMedia().mediaWithURL("url")

2.- Use the playback functions with VLCMediaPlayer or VLCMediaList

var instanciaVLCMediaList: VLCMediaList = VLCMediaList().initWithOptions(nil)

instanciaVLCMediaList.playMedia(instanciaVLCMedia)
    
answered by 24.10.2017 / 22:29
source