(原创)IOS播放视频
//创建播放器并播放视频。 -(void) playMovie{ NSString* videoPath = [[Globals getResourceManager] loadVideo:@"abcSong"]; player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; player.controlStyle = MPMovieControlStyleFullscreen; player.view.frame = [Globals getScreenRect]; player.initialPlaybackTime = -1; [self.view addSubview:player.view]; player.backgroundColor = [UIColor blackColor]; player.useApplicationAudioSession = NO; player.movieControlMode = MPMovieControlModeHidden; player.scalingMode = MPMovieScalingModeAspectFit; [player play];
//当视频播放结束释放资源。 -(void) movieFinishedCallback:(NSNotification*) aNotification{ [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player]; [player stop]; [player.view removeFromSuperview]; [player release]; player = nil; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步