实现在tableviewcell中进行播放视频

2017-08-07  本文已影响0人  眼睛不笑的人

因为链接中需要播放优酷视频,所以播放器使用webview进行播放

MPMoviePlayerController播放器的已经注释了, 如果只是单纯播放可以不使用webview

在tebleviewcell点击方法中加入如下代码

[self.player.viewremoveFromSuperview];

self.index= indexPath.row;

NSString*videoPath = [[self.videoArrobjectAtIndex:indexPath.row]objectForKey:@"videoPath"];

NSString*urlString =@"";

if([videoPathrangeOfString:@"http"].location!=NSNotFound) {

urlString = videoPath;

}else{

urlString = [NSStringstringWithFormat:@"%@%@",HTTP_URL_BUSSNIESS,videoPath];

}

NSURL*videomp4 = [NSURLURLWithString:urlString];

self.videoURL= videomp4;

[selfplayVieo];

之后实现[selfplayVieo];

ExhibitionTableViewCell*cell = (ExhibitionTableViewCell*)[self.viewviewWithTag:1000+self.index];

//self.player = [[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];

//[self.player prepareToPlay];

//[self.videoTableview addSubview:self.player.view];

//self.player.shouldAutoplay = YES;

//[self.player setControlStyle:MPMovieControlStyleEmbedded];

//

//[self.player setFullscreen:NO];

//[self.player.view setFrame:cell.videoImg.bounds];

self.videoWedView= [[UIWebViewalloc]initWithFrame:CGRectMake(0,200*self.index,self.view.frame.size.width,self.view.frame.size.width/2)];

[self.videoWedViewloadRequest:[NSURLRequestrequestWithURL:self.videoURL]];

[self.videoTableviewaddSubview:self.videoWedView];

[self.player.viewsetFrame:cell.videoImg.bounds];

//self.player.view.frame = CGRectMake(0 ,200 * self.index, self.view.frame.size.width, self.view.frame.size.width / 2);

self.closeButton= [UIButtonbuttonWithType:UIButtonTypeCustom];

self.closeButton.frame=CGRectMake(self.player.view.frame.size.width-35,10,30,30);

[self.closeButtonsetBackgroundImage:[UIImageimageNamed:@"ic_refrashbar_cancel_press.png"]forState:UIControlStateNormal];

[self.closeButtonaddTarget:selfaction:@selector(closeMovie:)forControlEvents:UIControlEventTouchUpInside];

[self.player.viewaddSubview:self.closeButton];

[selfaddNotification];

-(void)exitFullScreen:(NSNotification*)notification{

[self.playerplay];

}

-(void)jionFullScreen:(NSNotification*)notification{

[self.playerplay];

}

#pragma mark -控制器通知

-(void)addNotification{

NSNotificationCenter*center = [NSNotificationCenterdefaultCenter];

[centeraddObserver:selfselector:@selector(mediaPlayerPlaybackStateChange:)name:MPMoviePlayerPlaybackStateDidChangeNotificationobject:self.player];

[centeraddObserver:selfselector:@selector(mediaPlayerPlaybackFinished:)name:MPMoviePlayerPlaybackDidFinishNotificationobject:self.player];

[centeraddObserver:selfselector:@selector(mediaPlayerPlaybackAllping:)name:MPMoviePlayerWillEnterFullscreenNotificationobject:self.player];

}

-(void)mediaPlayerPlaybackStateChange:(NSNotification*)nsnotification{

switch(self.player.playbackState) {

caseMPMoviePlaybackStatePlaying:{

NSLog(@"正在播放...");

}break;

caseMPMoviePlaybackStatePaused:

NSLog(@"暂停播放.");

break;

caseMPMoviePlaybackStateStopped:

NSLog(@"停止播放.");

break;

default:

NSLog(@"播放状态:%li",(long)self.player.playbackState);

break;

}

}

-(void)mediaPlayerPlaybackFinished:(NSNotification*)notification{

NSLog(@"播放完成.%li",(long)self.player.playbackState);

NSLog(@"11111111111%f",self.player.currentPlaybackTime);

[self.playerstop];

[self.playerpause];

[self.player.viewremoveFromSuperview];

}

-(void)mediaPlayerPlaybackAllping:(NSNotification*)notification{

Fullscreen=YES;

}

- (void)closeMovie:(UIButton*)button {

[self.playerstop];

[self.playerpause];

[self.player.viewremoveFromSuperview];

}

-(void)exitFullScreennn:(NSNotification*)notification{

[self.playerstop];

[self.playerpause];

[self.player.viewremoveFromSuperview];

}

#pragma mark -解析

//视频

-(void)getVideoList

{

//1.创建网络请求(GET)

NSString*searchKey =self.mySearchBar.text;

NSString*str = [NSStringstringWithFormat:@"%@?currPage=%d&pageSize=%d&searchKey=%@",HTTP_URL_Get_VIDEO,CurrentPage,CellpageSize,searchKey];

NSURL*url=[NSURLURLWithString:str];

self.videoListRequest= [ASIHTTPRequestrequestWithURL:url];

self.videoListRequestData= [NSMutableDatanew];

[self.videoListRequestsetDelegate:self];

[self.videoListRequeststartAsynchronous];

}

//视频刷新

- (void)getVideoList:(NSInteger)page PageSize:(NSInteger)pageSize

{

//1.创建网络请求(GET)

NSString*searchKey =self.mySearchBar.text;

NSString*str = [NSStringstringWithFormat:@"%@?currPage=%ld&pageSize=%ld&searchKey=%@",HTTP_URL_Get_VIDEO, (long)page, (long)pageSize,searchKey];

NSURL*url=[NSURLURLWithString:str];

self.videoListRequest= [ASIHTTPRequestrequestWithURL:url];

self.videoListRequestData= [NSMutableDatanew];

[self.videoListRequestsetDelegate:self];

[self.videoListRequeststartAsynchronous];

}

- (void)requestFinished:(ASIHTTPRequest*)request{

[selfHiddenWaitingView];

//请求成功完成的时候调用

NSDictionary* dict = [NSJSONSerializationJSONObjectWithData:self.videoListRequestDataoptions:NSJSONReadingAllowFragmentserror:nil];

if(!PullTableLoad) {

self.videoArr= [NSMutableArraynew];

}

NSArray*dataArray = [dictvalueForKey:@"data"];

if([dataArraycount]>0){

self.videoArr= [self.videoArrarrayByAddingObjectsFromArray:dataArray];

//self.videoArr = dataArray;

}

for(intn =0; n<[dataArraycount]; n++) {

NSDictionary*oneDic = [dataArrayobjectAtIndex:n];

NSString*attentionCnt = [oneDicobjectForKey:@"attentionCnt"];

NSString*delFlg = [oneDicobjectForKey:@"delFlg"];

NSString*publisherId = [oneDicobjectForKey:@"publisherId"];

NSString*releaseTime = [oneDicobjectForKey:@"releaseTime"];

NSString*videoContent = [oneDicobjectForKey:@"videoDescription"];

NSString*videoId = [oneDicobjectForKey:@"videoId"];

NSString*videoImg = [oneDicobjectForKey:@"videoImg"];

NSString*videoPath = [oneDicobjectForKey:@"videoPath"];

NSString*videoTitle = [oneDicobjectForKey:@"videoTitle"];

NSString*videoWeight = [oneDicobjectForKey:@"videoWeight"];

videoInfo*video = [[videoInfoalloc]initWithVideoInfo:videoIdpublisherId:publisherIdreleaseTime:releaseTimevideoTitle:videoTitlevideoContent:videoContentvideoPath:videoPathvideoImg:videoImgvideoWeight:videoWeightdelFlg:delFlgattentionCnt:attentionCnt];

[self.videoListArrayaddObject:video];

}

[self.videoTableviewreloadData];

if(PullTableLoad) {

self.videoTableview.pullTableIsLoadingMore=NO;

PullTableLoad=NO;

}

if(PullTableRefresh) {

self.videoTableview.pullTableIsRefreshing=NO;

PullTableRefresh=NO;

}

}

上一篇下一篇

猜你喜欢

热点阅读