Playing Avi video in swift based application

1.8k views Asked by At

I'm trying to play a video of type avi in an application created in xcode written in swift. The thing is all of the videos I have are in avi and I cannot afford time spent converting the videos right now. Is there a way to play the video in the provided Media player library? the code I wrote plays the audio of the video only:

func playVideo() {
    let path = NSBundle.mainBundle().pathForResource(symbol, ofType:"avi")
    let url = NSURL.fileURLWithPath(path!)
    moviePlayer = MPMoviePlayerController(contentURL: url)
    if let player = moviePlayer {
        player.view.frame = self.view.bounds
        player.prepareToPlay()
        player.scalingMode = .AspectFill
        self.view.addSubview(player.view)
    }

or maybe there's a way to convert a video when the function is called?

1

There are 1 answers

0
zarghol On

I,

following the documentation of the MPMediaPlayer :

For movie files, this typically means files with the extensions .mov, .mp4, .mpv, and .3gp

So, unfortunately, you can't use the MPMediaPlayer to read your avi video.

Thanks to VLC for iOs source code, you can re-use it to implement a custom player to read these files.