2014-07-07 102 views
1

我想打從URL MP4格式的視頻通過HTTPS使用的MPMoviePlayerController播放MP4視頻,但視頻是不是在玩,我收到日誌錯誤:如何從URL通過HTTPS在iOS

_itemFailedToPlayToEnd: { 
kind = 1; 
new = 2; 
old = 0; 
} 

有沒有辦法在iOS上播放這種視頻?

這裏是我的代碼:

#import "FirstViewController.h" 
#import <MediaPlayer/MediaPlayer.h> 

@interface FirstViewController() 

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer; 

@end 

@implementation FirstViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [self playBtnPressed]; 
} 

-(void)playBtnPressed 
{ 
    NSURL *url=[[NSURL alloc] initWithString:@"https://....mp4"]; 
    _moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:_moviePlayer]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDonePressed:) name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer]; 

    _moviePlayer.controlStyle=MPMovieControlStyleDefault; 
    //moviePlayer.shouldAutoplay=NO; 
    [_moviePlayer play]; 
    [self.view addSubview:_moviePlayer.view]; 
    [_moviePlayer setFullscreen:YES animated:YES]; 
} 

- (void) moviePlayBackDonePressed:(NSNotification*)notification 
{ 
    [_moviePlayer stop]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer]; 


    if ([_moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) 
    { 
     [_moviePlayer.view removeFromSuperview]; 
    } 
    _moviePlayer=nil; 
} 

- (void) moviePlayBackDidFinish:(NSNotification*)notification 
{ 
    [_moviePlayer stop]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:_moviePlayer]; 

    if ([_moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) 
    { 
     [_moviePlayer.view removeFromSuperview]; 
    } 
} 

@end 
+0

向我們顯示您的代碼。 – Neeku

+0

PLease向我們展示您的代碼,在其中設置MPMoviePlayerController – jithinroy

+0

我剛剛通過添加代碼編輯我的文章 – saltwat5r

回答

0

大概視頻寬高比問題嘗試設置寬高比

[player setScalingMode:MPMovieScalingModeAspectFit]; player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

或檢查如果視頻文件是有指定的URL位置

+0

視頻文件存在於URL。 – saltwat5r

+0

它不適合我:/ – saltwat5r

0

這似乎是一個iOS 7問題。 顯然,moviePlayer.movi​​eSourceType = MPMovieSourceTypeStreaming;不再工作了。 對我來說,用MPMovieSourceTypeFile替換它解決了這個錯誤。 使用下面的代碼它會爲你工作。請確保您在播放電影之前已聲明通知觀察員,如下所示:

[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(moviePlayBackDidFinish:) 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:moviePlayerController.moviePlayer]; 

     moviePlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 

     [moviePlayerController.moviePlayer prepareToPlay]; 

     [self presentMoviePlayerViewControllerAnimated:moviePlayerController]; 

     [moviePlayerController.moviePlayer play]; 
+0

我的帖子編輯 – saltwat5r

+0

無論我在這裏粘貼的是解決問題的方法...請通過它,讓我知道它是否工作。 – Adi

+0

我試過了,它不工作。 – saltwat5r