MPMoviePlayerController
現在、アプリで動画を再生するために使用しています。あるビデオから次のビデオに切り替えるとき、それはあまりスムーズな移行ではありません。私がする必要があるのは、最初のビデオをフェードアウトし、2番目のビデオをフェードインすることであるという結論に達しました。これを行うには、2つのビデオを同時に再生する必要があります。私はそれができないことを知っていますMPMoviePlayerController
。それはドキュメントにあります。それはで行うことができますAVPlayer
か?AVPlayer
異なる映画を再生し、アプリで同時に再生し、両方の映画をユーザーに表示するという2つのインスタンスを作成できますか?
7338 次
4 に答える
4
MPMoviePlayer を使用して一度に再生できるムービーは 1 つだけです。ただし、AVPlayer を使用して複数のビデオを同時に再生できます (AVFoundation では、低レベルのオーディオ ビデオ フレームワーク)。次の例を確認してください。
于 2012-01-24T17:39:25.420 に答える
0
一度に 8 つ再生してから、スクロールしてさらに 8 つ再生する方法は次のとおりです。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = (UICollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifier forIndexPath:indexPath];
// Enumerate array of visible cells' indexPaths to find a match
if ([self.collectionView.indexPathsForVisibleItems
indexOfObjectPassingTest:^BOOL(NSIndexPath * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
return (obj.item == indexPath.item);
}]) dispatch_async(dispatch_get_main_queue(), ^{
[self drawLayerForPlayerForCell:cell atIndexPath:indexPath];
});
return cell;
}
- (void)drawPosterFrameForCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
[self.imageManager requestImageForAsset:AppDelegate.sharedAppDelegate.assetsFetchResults[indexPath.item]
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeAspectFill
options:nil
resultHandler:^(UIImage *result, NSDictionary *info) {
cell.contentView.layer.contents = (__bridge id)result.CGImage;
}];
}
- (void)drawLayerForPlayerForCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
cell.contentView.layer.sublayers = nil;
[self.imageManager requestPlayerItemForVideo:(PHAsset *)self.assetsFetchResults[indexPath.item] options:nil resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) {
dispatch_sync(dispatch_get_main_queue(), ^{
if([[info objectForKey:PHImageResultIsInCloudKey] boolValue]) {
[self drawPosterFrameForCell:cell atIndexPath:indexPath];
} else {
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:[AVPlayer playerWithPlayerItem:playerItem]];
[playerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[playerLayer setBorderColor:[UIColor whiteColor].CGColor];
[playerLayer setBorderWidth:1.0f];
[playerLayer setFrame:cell.contentView.layer.bounds];
[cell.contentView.layer addSublayer:playerLayer];
[playerLayer.player play];
}
});
}];
}
このdrawPosterFrameForCell
メソッドは、デバイスではなく iCloud に保存されているため、ビデオを再生できない場所に画像を配置することに注意してください。
于 2016-06-15T10:45:38.090 に答える
-1
MPMoviePlayerController
一度に1つのビデオのみを再生します。
ただし、を使用して複数のビデオを同時に再生できますAVPlayer
。
以下は、複数のビデオを同時に再生するためのチュートリアルリンクです-ビデオを同時に再生する
于 2012-02-01T12:06:46.190 に答える
-2
iOS アプリで 2 つのビデオを同時に再生する場合は、AVPlayer を使用してビデオを再生します。
于 2012-06-22T06:53:53.960 に答える