Ios 全屏播放YouTube视频
我想使用YouTube Helper在我的应用程序中播放YouTube视频。我希望在表格视图单元格中显示YTPlayerView,当点击视频时,我希望它以全屏模式开始播放。 然而,当我试用YouTube助手时,它会在线播放视频,不会扩展到全屏。Ios 全屏播放YouTube视频,ios,youtube,youtube-iframe-api,ytplayerview,Ios,Youtube,Youtube Iframe Api,Ytplayerview,我想使用YouTube Helper在我的应用程序中播放YouTube视频。我希望在表格视图单元格中显示YTPlayerView,当点击视频时,我希望它以全屏模式开始播放。 然而,当我试用YouTube助手时,它会在线播放视频,不会扩展到全屏。 有没有办法让YouTube helper立即全屏播放视频 实际上这很容易。下面是在表格单元格中显示YTPlayerView的代码。点击YouTube缩略图以全屏播放 创建自定义表格视图单元格。在Interface Builder中,将视图拖动到单元格中,
有没有办法让YouTube helper立即全屏播放视频 实际上这很容易。下面是在表格单元格中显示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
以下是报春花在Swift 2.2中的答案: 表视图单元格:
import UIKit
class VideoCellTableViewCell: UITableViewCell {
@IBOutlet var playerView: YTPlayerView!
var isLoaded = false
}
TableViewController:
- (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;
}
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!
}