我想使用 YouTube Helper https://github.com/youtube/youtube-ios-player-helper在我的应用中播放 YouTube 视频。我想在表格视图单元格中显示 YTPlayerView,当点击视频时,我希望它开始以全屏模式播放。但是,当我试用 YouTube 助手时,它会内联播放视频并且不会扩展到全屏。有什么方法可以让视频立即全屏播放 YouTube 助手?
问问题
3128 次
2 回答
1
其实这很容易。这是在表格单元格中显示 YTPlayerView 的代码。点击 YouTube 缩略图以全屏播放。
创建自定义表格视图单元格。在 Interface Builder 中,将视图拖到您的单元格中,将类更改为 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;
}
于 2016-02-04T11:22:20.810 回答
0
这是 Primulaveris 在 Swift 2.2 中的回答:
表格视图单元格:
import UIKit
class VideoCellTableViewCell: UITableViewCell {
@IBOutlet var playerView: YTPlayerView!
var isLoaded = false
}
表视图控制器:
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!
}
于 2016-08-29T16:25:41.283 回答