Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView with multiple AVPlayerViews
    primarykey
    data
    text
    <p>i need your help. I want to create a horizontal <code>ScrollView</code> with some <code>AVPlayers</code>. I tried this <code>ScrollView</code> with some pictures and it works. The problem now is that i can scroll due the <code>View</code>, but all the <code>AVPlayerViews</code> are at the same position, so i just can see the last-loaded video and all the other scroll positions are blank.</p> <p>This is the source of my class:</p> <pre><code>@implementation VPVideoScroller const CGFloat kScrollObjHeight = 748.0; const CGFloat kScrollObjWidth = 1024.0; NSUInteger numImages = 0; - (void)viewDidLoad { numImages = _pictureArray.count; [super viewDidLoad]; self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor]; // 1. setup the scrollview for multiple images and add it to the view controller self.scrollView.clipsToBounds = YES; // load all the images from our bundle and add them to the scroll view NSUInteger i; for (i = 1; i &lt;= numImages; i++) { if (i&lt;3) { /* //------------ MPMediaItem *item = [self.pictureArray objectAtIndex:(i-1)]; NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL]; */ AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:self.currentURL]; AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem]; //------------ UIView *imageView = [[UIView alloc] init]; AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; [player play]; /* UIImage *image = [self.pictureArray objectAtIndex:(i-1)]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; */ // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList" CGRect rect = imageView.frame; rect.size.height = kScrollObjHeight; rect.size.width = kScrollObjWidth; imageView.frame = rect; imageView.tag = i; // tag our images for later use when we place them in serial fashion imageView.contentMode = UIViewContentModeScaleAspectFit; [imageView.layer addSublayer:playerLayer]; playerLayer.frame = imageView.layer.bounds; [self.scrollView addSubview:imageView]; } } [self layoutScrollImages]; // now place the photos in serial layout within the scrollview } - (void)layoutScrollImages { UIImageView *view = nil; NSArray *subviews = [self.scrollView subviews]; // reposition all image subviews in a horizontal serial fashion CGFloat curXLoc = 0; for (view in subviews) { if ([view isKindOfClass:[UIImageView class]] &amp;&amp; view.tag &gt; 0) { CGRect frame = view.frame; frame.origin = CGPointMake(curXLoc, 0); view.frame = frame; curXLoc += (kScrollObjWidth); } } // set the content size so it can be scrollable //[self.scrollView setContentSize:CGSizeMake((numImages * kScrollObjWidth), [self.scrollView bounds].size.height)]; [self.scrollView setContentSize:CGSizeMake((numImages * kScrollObjWidth), kScrollObjHeight)]; } </code></pre> <p>The <code>pictureArray</code> contains an <code>Array</code> of URLs, but they are all the same. So <code>AVPlayers</code> should show all the same video.</p> <p><img src="https://i.stack.imgur.com/SxcO0.jpg" alt="UIScrollView"></p> <p>Thank you in advance. Kevin</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload