2016-01-14 129 views
1

我想使用YouTube帮助https://github.com/youtube/youtube-ios-player-helper在我的应用中播放YouTube视频。我想在表格视图单元格中显示YTPlayerView,当点击视频时,我希望它以全屏模式开始播放。 但是,当我尝试使用YouTube帮助程序时,它会以串联方式播放视频,并且不会展开为全屏。 有没有什么方法让视频立即与YouTube助手一起播放全屏?播放YouTube视频全屏

回答

0

这里是Primulaveris'斯威夫特2.2答案:

表格视图单元格:

import UIKit 
class VideoCellTableViewCell: UITableViewCell { 
    @IBOutlet var playerView: YTPlayerView! 
    var isLoaded = false 
} 

TableViewController:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    var cell = (tableView!.dequeueReusableCellWithIdentifier("VideoCell", forIndexPath: indexPath!)! as! VideoCellTableViewCell) 
    cell.playerView.stopVideo() 
    if cell.isLoaded { 
     cell.playerView.loadWithVideoId("your video ID") 
     cell.isLoaded = true 
    } 
    else { 
     // avoid reloading the player view, use cueVideoById instead 
     cell.playerView.cueVideoById("your video ID", startSeconds: 0, suggestedQuality: kYTPlaybackQualityDefault) 
    } 
    return cell! 
} 
1

其实这很简单。这是用于在表格单元格中显示YTPlayerView的代码。点按YouTube缩略图以全屏播放。

创建自定义表格视图单元格。在界面构建器中,将视图拖到单元格中,将类更改为YTPlayerView并将其与您单元格的playerView属性挂钩。

#import <UIKit/UIKit.h> 
#import "YTPlayerView.h" 
@interface VideoCellTableViewCell : UITableViewCell 
@property (nonatomic, strong) IBOutlet YTPlayerView *playerView; 
@property (assign) BOOL isLoaded; 
@end 

在您的视图控制器:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    VideoCellTableViewCell *cell = (VideoCellTableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"VideoCell" forIndexPath:indexPath]; 
    [cell.playerView stopVideo]; 
    if (!cell.isLoaded) { 
     [cell.playerView loadWithVideoId:@"your video ID"]; 
     cell.isLoaded = YES; 
    } 
    else { 
     // avoid reloading the player view, use cueVideoById instead 
     [cell.playerView cueVideoById:@"your video ID" startSeconds:0 suggestedQuality:kYTPlaybackQualityDefault]; 
    } 
return cell; 
} 
+1

是否有一个等效的swift代码? – Pangu