私は2つのAVPlayersを持つUITableViewセルを持っています。右側に1つ、左側に1つ。これと一緒に行くには、2 AVPlayerLayers、2 AVPlayerItemsなど、セルの両側に正確に同じ設定。ただし、セルの右側のビデオは再生されません。セルの左側のAVPlayerは完全に機能します。セルの右側のAVPlayerが動作しない
- (void)playVideoOnLeftFromCache:(CompletedTableViewCell *)videoCell {
videoCell.contentView.backgroundColor = [UIColor clearColor];
videoCell.redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, (videoCell.frame.size.width/2), 255)];
[videoCell.contentView insertSubview:videoCell.redView aboveSubview:videoCell.blueView];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *mov = @".mov";
NSString *fullComponent = [NSString stringWithFormat: @"%@%@", self.videoChallengeID1, mov];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:fullComponent];
NSURL *url = [NSURL fileURLWithPath:fullPath];
videoCell.item1 = [AVPlayerItem playerItemWithURL:url];
videoCell.player1 = [[AVPlayer alloc] initWithPlayerItem:videoCell.item1];
[videoCell.player1 setMuted:YES];
videoCell.player1.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(player1Finished:)
name:AVPlayerItemDidPlayToEndTimeNotification object:[videoCell.player1 currentItem]]; videoCell.playerLayer1 = [AVPlayerLayer playerLayerWithPlayer:videoCell.player1];
videoCell.playerLayer1.frame = CGRectMake(0, 0, (videoCell.frame.size.width/2), 255);
videoCell.playerLayer1.backgroundColor = [UIColor clearColor].CGColor;
videoCell.playerLayer1.videoGravity = AVLayerVideoGravityResize;
[videoCell.redView.layer addSublayer:videoCell.playerLayer1];
[videoCell.player1 play];
}
私が上で述べたように、それはうまく動作します。セルの右側のために、私はちょうど右側にそれを作るために周りにフレームを移動し、ほぼ同じコードを持っている:
- (void)playVideoOnRightFromCache:(CompletedTableViewCell *)videoCell {
videoCell.contentView.backgroundColor = [UIColor clearColor];
videoCell.redView2 = [[UIView alloc] initWithFrame:CGRectMake((videoCell.frame.size.width/2), 0, (videoCell.frame.size.width/2), 255)];
[videoCell.contentView insertSubview:videoCell.redView2 aboveSubview:videoCell.blueView2];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *mov = @".mov";
NSString *fullComponent = [NSString stringWithFormat: @"%@%@", self.videoChallengeID1, mov];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:fullComponent];
NSURL *url = [NSURL fileURLWithPath:fullPath];
videoCell.item2 = [AVPlayerItem playerItemWithURL:url];
videoCell.player2 = [[AVPlayer alloc] initWithPlayerItem:videoCell.item2];
[videoCell.player2 setMuted:YES];
videoCell.player2.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(player1Finished:)
name:AVPlayerItemDidPlayToEndTimeNotification object:[videoCell.player2 currentItem]];
videoCell.playerLayer2 = [AVPlayerLayer playerLayerWithPlayer:videoCell.player2];
videoCell.playerLayer2.frame = CGRectMake((videoCell.frame.size.width/2), 0, (videoCell.frame.size.width/2), 255);
videoCell.redView2.layer.backgroundColor = [UIColor orangeColor].CGColor;
videoCell.blueView2.backgroundColor = [UIColor blueColor];
videoCell.playerLayer2.videoGravity = AVLayerVideoGravityResize;
[videoCell.redView2.layer addSublayer:videoCell.playerLayer2];
// [videoCell.player2 addObserver:videoCell forKeyPath:@"status" options:0 context:nil];
[videoCell.player2 play];
}
私はどこをそれぞれ見ることができるようにここでの唯一の違いは、追加の背景色が変化していますビュー/レイヤーはです。現在、セルの右側の背景はオレンジ色で表示されています。つまり、実際には、redView2が正しいフレームを持っています。この後、私はサブレイヤとしてplayerLayer2を追加しますが、単に何も表示されません。その背景色を変更しようとすると、何も変わりません。私はkeyValueオブザーバーが準備ができたらビデオを再生するように設定しようとしましたが、それはどちらも助けにはなりませんでした。
ここで間違いがありますか?私は非常に混乱しています。これらの2つの状況は、フレームを除いてほぼ同じです。そして、それは単に動作しません。
@interface CompletedTableViewCell : UITableViewCell
// Video Players
@property (strong, nonatomic) AVPlayer *player1;
@property (strong, nonatomic) AVPlayer *player2;
@property (strong, nonatomic) AVPlayerItem *item1;
@property (strong, nonatomic) AVPlayerItem *item2;
@property (strong, nonatomic) AVPlayerLayer *playerLayer1;
@property (strong, nonatomic) AVPlayerLayer *playerLayer2;
@property (strong, nonatomic) UIView *redView;
@property (strong, nonatomic) UIView *blueView;
@property (strong, nonatomic) UIView *redView2;
@property (strong, nonatomic) UIView *blueView2;
@end
誰もが起こっていることができるものの任意のアイデアを持っている:任意のより詳細な情報が必要な場合
ただ、ここに私のUITableViewCellクラスですか?
ビデオは同じ層でも違うのですか? 'self.videoChallengeID1'を両方のプレーヤーにパスまたはURLとして渡しているからです。 – Lion
それぞれのプレーヤーのビデオが異なっています – joey
なぜあなたは両方に同じURLを渡していますか? – Lion