0

I'm trying to reproduce a video with MPMoviePlayerController by this way:

    var url:NSURL = NSURL(fileURLWithPath: "/var/mobile/Containers/Data/Application/D64F96C8-B00F-41D8-AC38-DB07121D00FA/Documents/video_comp.mov", isDirectory: false)

    if (NSFileManager.defaultManager().fileExistsAtPath(url.path!)) {
        println("FILE EXISTS") //File exists
    } else {
        println("FILE DOESN'T EXIST")
    }

    var moviePlayer = MPMoviePlayerController(contentURL: url)
    moviePlayer.view.frame = CGRectMake(0, 0, 200, 200)
    self.view.addSubview(moviePlayer.view)

    moviePlayer.scalingMode = MPMovieScalingMode.AspectFit
    moviePlayer.shouldAutoplay = true
    moviePlayer.prepareToPlay()

    if moviePlayer.isPreparedToPlay {
        println("PREPARED")
    } else {
        println("NOT PREPARED") //.isPreparedToPlay is always false
    }

    moviePlayer.play()

But it's never reproduced. First of all I checked if the file exists and it exists. Then I checked if moviePlayer isPrepraredToPlay but it seems is not prepared before playing. Do you have any idea why I can't reproduce it?

Thanks

Alex
  • 6,957
  • 12
  • 42
  • 48
  • 1
    http://stackoverflow.com/questions/25034497/playing-a-video-file-from-a-server-in-swift – user523234 Nov 05 '14 at 15:56
  • Thanks for your comment @user523234 I had tried to follow this answer but it doesn't works for me. Maybe there is an error building MPMoviePlayerController object. – Alex Nov 05 '14 at 16:45

1 Answers1

2

this is working for me:

 myPlayer = [[MPMoviePlayerController alloc] init];
[myPlayer setScalingMode:MPMovieScalingModeAspectFit];
// [myPlayer setControlStyle:MPMovieControlStyleFullscreen];
[myPlayer setContentURL:[NSURL fileURLWithPath:filePath]];
myPlayer.movieSourceType = MPMovieControlStyleEmbedded;
//myPlayer.fullscreen = YES;
myPlayer.view.frame = CGRectMake(0, 0, 200, 200);   //self.view.bounds;
[myPlayer prepareToPlay];
if(myPlayer.isPreparedToPlay){
    NSLog(@"preparada para verse!");
} else {
    NSLog(@"No preparada para verse!");
}
[self.view addSubview:myPlayer.view];
[myPlayer play];

In my app I use fullscreen video but I've put in comments the fullscreen code and I've changed self.view.bounds for your size: CGRectMake(0,0,200,200). The funny thing is that I also get the not prepared message but the video works perfect! I hope this help!

abanet
  • 1,327
  • 17
  • 22