Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: dev: start playing item from given moment #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AUMediaPlayer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Pod::Spec.new do |s|
s.framework = 'GoogleCast'
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '"${PODS_ROOT}/AUMediaPlayer/Frameworks/GoogleCastSDK-2.7.1-Release"' }

s.dependency 'AFNetworking', '> 2.3'
s.dependency 'AFNetworking'
#s.dependency 'google-cast-sdk', '~>2.7.1'

end
10 changes: 10 additions & 0 deletions Pod/Classes/AUMediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ typedef NS_ENUM(NSUInteger, AUMediaReceiverType){
* @param error Error is assigned when playback fails.
*/
- (void)playItem:(id<AUMediaItem>)item error:(NSError * __autoreleasing *)error;

/**
* Plays given item.
*
* @param item Item to play.
* @param moment Time in seconds, item will be sought to moment before starts playing
* @param error Error is assigned when playback fails.
*/
- (void)playItem:(id<AUMediaItem>)item fromMoment:(double)moment error:(NSError * __autoreleasing *)error;

/**
* Creates queue from mediaItems array of given collection and starts playing it starting from the first one.
*
Expand Down
21 changes: 18 additions & 3 deletions Pod/Classes/AUMediaPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@ - (void)setNowPlayingCover:(UIImage *)nowPlayingCover {
#pragma mark Player actions

- (void)playItem:(id<AUMediaItem>)item error:(NSError *__autoreleasing *)error {

[self playItem:item fromMoment:0 error:error];
}

- (void)playItem:(id<AUMediaItem>)item fromMoment:(double)moment error:(NSError *__autoreleasing *)error {
if (!item) {
NSAssert(NO, @"You must provide an item to play");
return;
}

[self updatePlayerWithItem:item error:error];
[self updatePlayerWithItem:item time:moment error:error];
self.queue = @[item];

if (_receiver == AUMediaReceiverChromecast) {
Expand Down Expand Up @@ -388,7 +391,7 @@ - (NSUInteger)queueLength {
#pragma mark -
#pragma mark Internal player methods

- (void)updatePlayerWithItem:(id<AUMediaItem>)item error:(NSError * __autoreleasing*)error {
- (void)updatePlayerWithItem:(id<AUMediaItem>)item time:(double)time error:(NSError * __autoreleasing*)error {
NSParameterAssert([item uid]);

[self prepareForCurrentItemReplacementWithItem:item];
Expand All @@ -414,7 +417,15 @@ - (void)updatePlayerWithItem:(id<AUMediaItem>)item error:(NSError * __autoreleas
return;
}

// create player item
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];

// time to seek
CMTime timeToSeek = CMTimeMakeWithSeconds(time, NSEC_PER_SEC);

// seek to time
[playerItem seekToTime:timeToSeek];

objc_setAssociatedObject(playerItem, AVPlayerItemAssociatedItem, item, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

if ([item itemType] == AUMediaTypeAudio) {
Expand Down Expand Up @@ -464,6 +475,10 @@ - (void)updatePlayerWithItem:(id<AUMediaItem>)item error:(NSError * __autoreleas
[self updateNowPlayingInfoCenterData];
}

- (void)updatePlayerWithItem:(id<AUMediaItem>)item error:(NSError * __autoreleasing*)error {
[self updatePlayerWithItem:item time:0.0 error:error];
}

- (void)initPlaybackTimeObserver {
double interval = .1f;

Expand Down