2009-10-10 33 views

Trả lời

17

MPMoviePlayerController là một đĩa đơn bên dưới mui xe. Nếu bạn chưa phát hành đúng cách (ObjC) hoặc Dispose() 'd (MonoTouch) và bạn tạo một bản sao thứ hai, nó sẽ không phát hoặc chỉ phát âm thanh.

Ngoài ra nếu bạn đăng ký MPMoviePlayerScalingModeDidChangeNotification hoặc MPMoviePlayerPlaybackDidFinishNotification hoặc MPMoviePlayerContentPreloadDidFinishNotification, được cảnh báo rằng các NSNotification posted mất một tham chiếu đến MPMoviePlayerController là tốt, vì vậy nếu bạn giữ nó xung quanh, bạn sẽ có một tài liệu tham khảo cho người chơi.

Mặc dù Bộ sưu tập rác của Mono cuối cùng sẽ khởi động, đây là trường hợp muốn hủy bỏ xác định (bạn muốn tham chiếu đi bây giờ, không biến mất khi GC quyết định thực hiện bộ sưu tập).

Đây là lý do tại sao bạn muốn gọi phương thức Dispose() trên bộ điều khiển và phương thức Dispose() trên thông báo.

Ví dụ:

// Deterministic termination, do not wait for the GC 
if (moviePlayer != null){ 
    moviePlayer.Dispose() 
    moviePlayer = null; 
} 

Nếu bạn được nghe thông báo, gọi Dispose trong xử lý thông báo của bạn ở cuối, để giải phóng tài liệu tham khảo mà nó giữ để MPMoviePlayerController của bạn ví dụ:

var center = NSNotificationCenter.DefaultCenter; 
center.AddObserver (
    "MPMoviePlayerPlaybackDidFinishNotification"), 
    (notify) => { Console.WriteLine ("Done!"); notify.Dispose(); }); 
0

Bí mật đặt trong endPlay với thiết lập: moviePlayer.initialPlaybackTime = -1; trước khi phát hành. Hãy thử nó ra: :)

-(void)playMovie:(NSString *)urlString{ 
    movieURL = [NSURL URLWithString:urlString]; 
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; 
    moviePlayer.initialPlaybackTime = 0; 
    //Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(endPlay:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:moviePlayer]; 

    moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
    moviePlayer.movieControlMode = MPMovieControlModeDefault; 
    moviePlayer.backgroundColor = [UIColor blackColor]; 

    [moviePlayer play]; 

} 

-(void)endPlay: (NSNotification*)notification{ 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 
    moviePlayer.initialPlaybackTime = -1; 
    [moviePlayer stop]; 
    [moviePlayer release]; 
} 
1

Không thể nhìn thấy mã của bạn Nir và tôi không có quyền chỉnh sửa vì vậy đây là một lần nữa:

Bí mật đặt trong endPlay với thiết lập: moviePlayer.initialPlaybackTime = -1; trước khi phát hành nó. Hãy dùng thử: :)

-(void)playMovie:(NSString *)urlString{ movieURL = [NSURL URLWithString:urlString];   
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];  
moviePlayer.initialPlaybackTime = 0; 
//Register to receive a notification when the movie has finished playing. 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endPlay:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 

moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
moviePlayer.movieControlMode = MPMovieControlModeDefault; 
moviePlayer.backgroundColor = [UIColor blackColor]; 

[moviePlayer play]; 

} 

-(void)endPlay: (NSNotification*)notification{ 
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 
moviePlayer.initialPlaybackTime = -1; 
[moviePlayer stop]; 
[moviePlayer release]; 
} 
Các vấn đề liên quan