Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Chat screen: BF: element-hq/element-ios#266 : Video playback stops wh…
Browse files Browse the repository at this point in the history
…en you rotate the device
  • Loading branch information
manuroe committed May 3, 2016
1 parent 51c3a49 commit c1ff5ed
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions MatrixKit/Controllers/MXKAttachmentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,8 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIV
navigationBarDisplayTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(hideNavigationBar) userInfo:self repeats:NO];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(coordinator.transitionDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

// Cell width will be updated, force collection refresh to take into account changes.
[_attachmentsCollection reloadData];
// Cell width will be updated, force collection layout refresh to take into account the changes
[_attachmentsCollection.collectionViewLayout invalidateLayout];

// Refresh the current attachment display
[self refreshAttachmentCollectionContentOffset];
Expand Down Expand Up @@ -254,7 +253,7 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
// Cell width will be updated, force collection refresh to take into account changes.
dispatch_async(dispatch_get_main_queue(), ^{

[_attachmentsCollection reloadData];
[_attachmentsCollection.collectionViewLayout invalidateLayout];

// Refresh the current attachment display
[self refreshAttachmentCollectionContentOffset];
Expand Down Expand Up @@ -686,7 +685,43 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
selectedCell.moviePlayer.view.center = selectedCell.customView.center;
selectedCell.moviePlayer.view.hidden = YES;
[selectedCell.customView addSubview:selectedCell.moviePlayer.view];

// Force the video to stay in fullscreen
NSLayoutConstraint* topConstraint = [NSLayoutConstraint constraintWithItem:selectedCell.moviePlayer.view
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:selectedCell.customView
attribute:NSLayoutAttributeTop
multiplier:1.0f
constant:0.0f];

NSLayoutConstraint *trailingConstraint = [NSLayoutConstraint constraintWithItem:selectedCell.moviePlayer.view
attribute:NSLayoutAttributeLeading
relatedBy:0
toItem:selectedCell.customView
attribute:NSLayoutAttributeLeading
multiplier:1.0
constant:0];

NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:selectedCell.moviePlayer.view
attribute:NSLayoutAttributeBottom
relatedBy:0
toItem:selectedCell.customView
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0];

NSLayoutConstraint *tailingConstraint = [NSLayoutConstraint constraintWithItem:selectedCell.moviePlayer.view
attribute:NSLayoutAttributeTrailing
relatedBy:0
toItem:selectedCell.customView
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:0];

selectedCell.moviePlayer.view.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[topConstraint, trailingConstraint, bottomConstraint, tailingConstraint]];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerPlaybackDidFinishNotification:)
name:MPMoviePlayerPlaybackDidFinishNotification
Expand Down

0 comments on commit c1ff5ed

Please sign in to comment.