iOS 5 an instance of AVPlayerItem was deallocated

前端 未结 3 419
情话喂你
情话喂你 2021-01-02 22:03

When I try to play a video from my iPhone (located in the documentsDirectory), I get the following error using iOS 5 while it was working fine with iOS 4.3:

An insta

3条回答
  •  抹茶落季
    2021-01-02 22:39

    EDIT: Just after posting the answer below I noticed that whenever the controller was reallocated, the errors came back as the old controller got automatically deallocated, even if I set up absolutely no notification handlers myself. Since the failures are coming from code inside the MP framework, I would say that this seems to be an OS bug.

    I encountered the same issue with a storyboard-based iOS 5 project using ARC. The problem is the use of a temporary variable on the stack to refer to the movie controller - in my case I assumed an interaction with ARC, but it may be more fundamental than that. In any event, it looks as if something gets deallocated/lost too early (e.g. when a playback error occurs) and the log gets filled with the sort of output you describe.

    Storing the movie controller reference in a property defined within the owning class solved this in my case; i.e:

    @interface MyClass
    @property ( strong, nonatomic ) MPMoviePlayerViewController * movieController;
    @end
    
    @@implementation MyClass
    @synthesize movieController = _movieController;
    
    // ...then later, this:
    //
    // MPMoviePlayerController *moviePlayerController = [...];
    //
    // ...becomes:
    
    self.movieController = [...];
    

    If you're using synthesised accessors for the property then whether you're using manual or automatic reference counting the generated setter method should correctly deallocate the old movie controller (if there is one) before setting up the new one.

    As a footnote, if you (say) dealloc/'unreference' (set-to-nil) the property manually in a MPMoviePlayerPlaybackDidFinishNotification notification handler then you'll probably notice that the errors come back. So don't do that :-)

提交回复
热议问题