怎么实现iphone播放在线视频呢?

iOS 码拜 9年前 (2015-05-09) 561次浏览 0个评论
 

请问各位朋友,如何实现在iphone上直接播放在线的视频呢

在线等
50分
-(id)init
{
	if(self = [super init])
	{
		[[NSNotificationCenter defaultCenter] addObserver:self 
		 selector:@selector(moviePreloadDidFinish:) 
		 name:MPMoviePlayerContentPreloadDidFinishNotification 
		 object:nil];
		 
		 // Register to receive a notification when the movie has finished playing. 
		 [[NSNotificationCenter defaultCenter] addObserver:self 
		 selector:@selector(moviePlayBackDidFinish:) 
		 name:MPMoviePlayerPlaybackDidFinishNotification 
		 object:nil];
		 
		 // Register to receive a notification when the movie scaling mode has changed. 
		 [[NSNotificationCenter defaultCenter] addObserver:self 
		 selector:@selector(movieScalingModeDidChange:) 
		 name:MPMoviePlayerScalingModeDidChangeNotification 
		 object:nil];
		return self;

	}
	return nil;
}



-(void)playMovie:(Contentinfo*)info
{


	if (moviePlayer != nil) 
	{
		[moviePlayer release];
		moviePlayer = nil;
	}
	NSURL* url = nil;

	if ([info.pathUrl hasPrefix:@"http://"])
	{

		url = [NSURL URLWithString:info.pathUrl];
	}
	else 
	{

		NSString* fullPath = [DataUtil getContentFilePath:info.pathUrl];
		NSLog(@"%@",fullPath);
		url = [NSURL fileURLWithPath:fullPath];
	}

	if (url != nil) 
	{
		moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
		moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
		moviePlayer.movieControlMode = MPMovieControlModeDefault;
		musicIsPlaying = [[MusicPlayerEngine shareInstence] isPlaying];
		if (musicIsPlaying) 
		{
			[[MusicPlayerEngine shareInstence] pause];
		}


		self.Info=info;


		[moviePlayer play];
	}


}

//视频已准备好播放
- (void) moviePreloadDidFinish:(NSNotification*)notification
{
	NSArray *windows = [[UIApplication sharedApplication] windows];
	if ([windows count] > 1)
	{
		UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
		UIImageView* view = (UIImageView*)[moviePlayerWindow viewWithTag:LOADING_VIEW_TAG];
		if (view != nil) {
			[view removeFromSuperview];
		}
	}


	if (0==[[notification userInfo] count])
	{	//将系统时间给contentInfo对象
		NSString *a=[NSString stringWithString:[self getTime]];
		Info.lastPlayedTime=a;
		//将contentInfo对象添加到最近播放列表
		[[DataBase sharedInstance] addContentInfoToRecentPlayList:self.Info];
	}

    NSLog(@"moviePreloadDidFinish");
}
//视频已播放结束
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
    NSLog(@"moviePlayBackDidFinish");

	          

	if (musicIsPlaying) {
		[[MusicPlayerEngine shareInstence] playMusic];
	}
	//begin zhaozhou mv播放界面退出后,刷新最近播放界面
	[self.delegate reloadRecentPlayTableView:self];
	//end

}
//视频比例模式发生改变。
- (void) movieScalingModeDidChange:(NSNotification*)notification
{
    NSLog(@"movieScalingModeDidChange");

}


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么实现iphone播放在线视频呢?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!