我想打從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
向我們顯示您的代碼。 – Neeku
PLease向我們展示您的代碼,在其中設置MPMoviePlayerController – jithinroy
我剛剛通過添加代碼編輯我的文章 – saltwat5r