實(shí)現(xiàn)在tableviewcell中進(jìn)行播放視頻

因?yàn)殒溄又行枰シ艃?yōu)酷視頻,所以播放器使用webview進(jìn)行播放

MPMoviePlayerController播放器的已經(jīng)注釋了, 如果只是單純播放可以不使用webview

在tebleviewcell點(diǎn)擊方法中加入如下代碼

[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];

之后實(shí)現(xiàn)[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(@"播放狀態(tài):%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.創(chuàng)建網(wǎng)絡(luò)請求(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.創(chuàng)建網(wǎng)絡(luò)請求(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];

//請求成功完成的時候調(diào)用

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;

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市暖侨,隨后出現(xiàn)的幾起案子驾中,更是在濱河造成了極大的恐慌澜掩,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,123評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件银酗,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)窥浪,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,031評論 2 384
  • 文/潘曉璐 我一進(jìn)店門祖很,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人漾脂,你說我怎么就攤上這事假颇。” “怎么了骨稿?”我有些...
    開封第一講書人閱讀 156,723評論 0 345
  • 文/不壞的土叔 我叫張陵笨鸡,是天一觀的道長。 經(jīng)常有香客問我坦冠,道長形耗,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,357評論 1 283
  • 正文 為了忘掉前任蓝牲,我火速辦了婚禮趟脂,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘例衍。我一直安慰自己昔期,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,412評論 5 384
  • 文/花漫 我一把揭開白布佛玄。 她就那樣靜靜地躺著硼一,像睡著了一般。 火紅的嫁衣襯著肌膚如雪梦抢。 梳的紋絲不亂的頭發(fā)上般贼,一...
    開封第一講書人閱讀 49,760評論 1 289
  • 那天,我揣著相機(jī)與錄音奥吩,去河邊找鬼哼蛆。 笑死,一個胖子當(dāng)著我的面吹牛霞赫,可吹牛的內(nèi)容都是我干的腮介。 我是一名探鬼主播,決...
    沈念sama閱讀 38,904評論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼端衰,長吁一口氣:“原來是場噩夢啊……” “哼叠洗!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起旅东,我...
    開封第一講書人閱讀 37,672評論 0 266
  • 序言:老撾萬榮一對情侶失蹤灭抑,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后抵代,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體腾节,經(jīng)...
    沈念sama閱讀 44,118評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,456評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了禀倔。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片榄融。...
    茶點(diǎn)故事閱讀 38,599評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖救湖,靈堂內(nèi)的尸體忽然破棺而出愧杯,到底是詐尸還是另有隱情,我是刑警寧澤鞋既,帶...
    沈念sama閱讀 34,264評論 4 328
  • 正文 年R本政府宣布力九,位于F島的核電站,受9級特大地震影響邑闺,放射性物質(zhì)發(fā)生泄漏跌前。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,857評論 3 312
  • 文/蒙蒙 一陡舅、第九天 我趴在偏房一處隱蔽的房頂上張望抵乓。 院中可真熱鬧,春花似錦靶衍、人聲如沸灾炭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,731評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蜈出。三九已至,卻和暖如春涛酗,著一層夾襖步出監(jiān)牢的瞬間铡原,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,956評論 1 264
  • 我被黑心中介騙來泰國打工商叹, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留燕刻,地道東北人。 一個月前我還...
    沈念sama閱讀 46,286評論 2 360
  • 正文 我出身青樓剖笙,卻偏偏與公主長得像酌儒,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子枯途,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,465評論 2 348

推薦閱讀更多精彩內(nèi)容