MPMoviePlayerPlaybackDidFinishNotification is called immediately

后端 未结 3 1315
孤独总比滥情好
孤独总比滥情好 2020-12-22 08:45

I\'m trying to play video with the following code:

UIGraphicsBeginImageContext(CGSizeMake(1,1));

self.player = [[MPMoviePlayerViewController alloc] initWith         


        
相关标签:
3条回答
  • 2020-12-22 09:22

    If the video plays on your desktop machine, but not iOS (either in-app or in Safari), it's most likely because the HTTP server does not support byte-range requests. If the HTTP server does not support byte-range requests, iOS will not play the video. This differs from Safari on OS X, which plays the video regardless.

    From the Safari Web Content Documentation:

    HTTP servers hosting media files for iOS must support byte-range requests, which iOS uses to perform random access in media playback. (Byte-range support is also known as content-range or partial-range support.) Most, but not all, HTTP 1.1 servers already support byte-range requests.

    Also, the HTTP server must provide a valid Content-Type header (the URL above also enumerates the valid MIME types). iOS will not play the video if the MIME type is invalid or missing.

    0 讨论(0)
  • 2020-12-22 09:25

    Try insert this:

    [[NSNotificationCenter defaultCenter] removeObserver: self.player
                                                    name: MPMoviePlayerPlaybackDidFinishNotification
                                                  object: self.player.moviePlayer];
    

    before

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player.moviePlayer]; 
    
    0 讨论(0)
  • 2020-12-22 09:31

    I'am not sure why, but with remote url's I realized in a past project that you need to add the observer without object as reference.... If you ask me why, I am not sure. Try adding the observer with nil as object...

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    
    0 讨论(0)
提交回复
热议问题