2

I am new at Swift Language. I want to develop simple movie player app for learning. I added some movies(".avi, .flv, .f4u.... which format is best) to my project. My view is just simple.There is a button on my view. ITs called "Play". When user tap on that button the movies will start.

Plus I need to play audio files too, like mp3 or .mid files. Can you give me how i can do that in Swift? IF you explain with example, It will be perfect.

Edit

I am not asking all code. I get confused when I try to convert my Objective C code to Swift. I want to know how I can develop below code in Swift?

NSString *path = [[NSBundle mainBundle] pathForResource:@"eminem1" ofType:@"mp4"];   

MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Antiokhos
  • 2,944
  • 5
  • 23
  • 32
  • 1
    Please notice that StackOverflow is for solving specific issues, not providing tutorials or answers to very broad questions like this. There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. – Neeku Aug 14 '14 at 16:26
  • Why downvote on that? i am not asking all code or project. Just I am trying to convert my old project from objective C to Swift. And get confuse on "just play a video" section.. Anyway sorry if it is not the place to ask... – Antiokhos Aug 14 '14 at 16:34
  • 1
    I haven't downvoted your question @Antiokhos, but your original post was too broad and low quality. Those who have downvoted, should revise and remove it after your edit; but still, people can downvote for any reason, and it's not even fair sometimes, but we can't do anything about it, since it's *their opinion*! – Neeku Aug 15 '14 at 08:52

2 Answers2

6

Try this:

    let path = NSBundle.mainBundle().pathForResource("eminem1", ofType: "mp4")
    let pathURL = NSURL.fileURLWithPath(path)

    let myPlayer = MPMoviePlayerViewController(contentURL: pathURL)
    myPlayer.moviePlayer.repeatMode = .None

    presentMoviePlayerViewControllerAnimated(myPlayer)

Don't forget import MediaPlayer.

Essan Parto
  • 703
  • 11
  • 18
0

Selected answer is deprecatedfor iOS 9+ versions.

Use this answer instead: How to play a local video with Swift?

Ahmadreza
  • 6,950
  • 5
  • 50
  • 69