Skip to content

Commit

Permalink
Some minor interface changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
blommegard committed Oct 11, 2013
1 parent b5a1b14 commit 356bff6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 40 deletions.
7 changes: 2 additions & 5 deletions HSPlayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
@interface HSPlayerView : UIView
@property (nonatomic, strong, readonly) AVPlayer *player;

// Start player by setting the URL (for a start)
// Start player by setting the URL
@property (nonatomic, copy) NSURL *URL;

- (void)play:(id)sender;
- (void)pause:(id)sender;

- (BOOL)isPlaying;
@property (nonatomic, assign) BOOL playing;

@property (nonatomic, assign) BOOL controlsVisible;
- (void)setControlsVisible:(BOOL)controlsVisible animated:(BOOL)animated;
Expand Down
61 changes: 31 additions & 30 deletions HSPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
// Enable buttons & scrubber

if (!self.isScrubbing)
[self play:self];
[self setPlaying:YES];
}
break;

Expand Down Expand Up @@ -226,7 +226,7 @@ - (AVPlayerLayer *)playerLayer {
}

- (void)setURL:(NSURL *)URL {
_URL = URL;
_URL = [URL copy];

// Create Asset, and load

Expand Down Expand Up @@ -266,6 +266,31 @@ - (void)setControlsVisible:(BOOL)controlsVisible {
[self setControlsVisible:controlsVisible animated:NO];
}

- (void)setPlaying:(BOOL)playing {
if (playing) {
if (self.seekToZeroBeforePlay) {
[self setSeekToZeroBeforePlay:NO];
[self.player seekToTime:kCMTimeZero];
}

[self.player play];

if (self.controlsVisible)
[self triggerAutoHideControlsTimer];
}
else {
[self.player pause];

if (self.controlsVisible)
[self cancelAutoHideControlsTimer];
}
}

- (BOOL)playing {
// return mRestoreAfterScrubbingRate != 0.f ||
return (self.player.rate > 0.);
}

#pragma mark - Controls

- (NSArray *)controls {
Expand Down Expand Up @@ -385,31 +410,7 @@ - (UITapGestureRecognizer *)doubleTapRecognizer {
return _doubleTapRecognizer;
}

#pragma mark Public

- (void)play:(id)sender {
if (self.seekToZeroBeforePlay) {
[self setSeekToZeroBeforePlay:NO];
[self.player seekToTime:kCMTimeZero];
}

[self.player play];

if (self.controlsVisible)
[self triggerAutoHideControlsTimer];
}

- (void)pause:(id)sender {
[self.player pause];

if (self.controlsVisible)
[self cancelAutoHideControlsTimer];
}

- (BOOL)isPlaying {
// return mRestoreAfterScrubbingRate != 0.f ||
return (self.player.rate != 0.);
}
#pragma mark - Public

- (void)setControlsVisible:(BOOL)controlsVisible animated:(BOOL)animated {
[self willChangeValueForKey:@"controlsVisible"];
Expand Down Expand Up @@ -459,7 +460,7 @@ - (void)cancelAutoHideControlsTimer {
- (void)toggleControlsWithRecognizer:(UIGestureRecognizer *)recognizer {
[self setControlsVisible:(!self.controlsVisible) animated:YES];

if (self.controlsVisible && self.isPlaying)
if (self.controlsVisible && self.playing)
[self triggerAutoHideControlsTimer];
}

Expand Down Expand Up @@ -571,11 +572,11 @@ - (void)removePlayerTimeObserver {
}

- (void)playPause:(id)sender {
[self isPlaying] ? [self pause:sender] : [self play:sender];
[self setPlaying:!self.playing];
}

- (void)syncPlayPauseButton {
[self.playPauseControlButton setImage:([self isPlaying] ? self.pauseImage : self.playImage) forState:UIControlStateNormal];
[self.playPauseControlButton setImage:(self.playing ? self.pauseImage : self.playImage) forState:UIControlStateNormal];
}

- (void)beginScrubbing:(id)sender {
Expand Down
7 changes: 2 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ Interface:
```objective-c
@property (nonatomic, strong, readonly) AVPlayer *player;

// Start player by setting the URL (for a start)
// Start player by setting the URL
@property (nonatomic, copy) NSURL *URL;

- (void)play:(id)sender;
- (void)pause:(id)sender;

- (BOOL)isPlaying;
@property (nonatomic, assign) BOOL playing;

@property (nonatomic, assign) BOOL controlsVisible;
- (void)setControlsVisible:(BOOL)controlsVisible animated:(BOOL)animated;
Expand Down

0 comments on commit 356bff6

Please sign in to comment.