Skip to content

Android preloading and playing at given time bugfixes #8

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

Open
wants to merge 1 commit into
base: apportable
Choose a base branch
from
Open
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
27 changes: 19 additions & 8 deletions ObjectAL/ObjectAL/AudioTrack/OALAudioTrack.m
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ - (void) dealloc
player.delegate = nil;
#elif __CC_PLATFORM_ANDROID
[player setOnCompletionListener:nil];
[player removeRef];
#endif
[player stop];

Expand Down Expand Up @@ -777,17 +778,18 @@ - (bool) preloadUrl:(NSURL*) url seekTime:(NSTimeInterval)seekTime
[assetFd close];
}

__weak id weakSelf = self;
__weak typeof (self) weakSelf = self;
[player setOnCompletionListener:[AndroidMediaPlayerOnCompletionListener listenerWithBlock:^(AndroidMediaPlayer *mp) {
[weakSelf onCompletion:mp];
__strong typeof (self) strongSelf = weakSelf;
[strongSelf onCompletion:mp];
}]];
#endif
as_release(currentlyLoadedUrl);
currentlyLoadedUrl = as_retain(url);
self.currentTime = seekTime;
playing = NO;
paused = NO;
self.currentTime = seekTime;
playing = NO;
paused = NO;

#if __CC_PLATFORM_IOS || __CC_PLATFORM_MAC
BOOL allOK = [player prepareToPlay];
Expand Down Expand Up @@ -815,7 +817,11 @@ - (bool) preloadFile:(NSString*) path

- (bool) preloadFile:(NSString*) path seekTime:(NSTimeInterval)seekTime
{
return [self preloadUrl:[OALTools urlForPath:path] seekTime:seekTime];
#if __CC_PLATFORM_IOS || __CC_PLATFORM_MAC
return [self preloadUrl:[OALTools urlForPath:path] seekTime:seekTime];
#elif __CC_PLATFORM_ANDROID
return [self preloadUrl:[NSURL fileURLWithPath:path] seekTime:seekTime];
#endif
}

- (bool) preloadUrlAsync:(NSURL*) url target:(id) target selector:(SEL) selector
Expand All @@ -839,7 +845,11 @@ - (bool) preloadFileAsync:(NSString*) path target:(id) target selector:(SEL) sel

- (bool) preloadFileAsync:(NSString*) path seekTime:(NSTimeInterval)seekTime target:(id) target selector:(SEL) selector
{
return [self preloadUrlAsync:[OALTools urlForPath:path] seekTime:seekTime target:target selector:selector];
#if __CC_PLATFORM_IOS || __CC_PLATFORM_MAC
return [self preloadUrlAsync:[OALTools urlForPath:path] seekTime:seekTime target:target selector:selector];
#elif __CC_PLATFORM_ANDROID
return [self preloadUrlAsync:[NSURL fileURLWithPath:path] seekTime:seekTime target:target selector:selector];
#endif
}

- (bool) playUrl:(NSURL*) url
Expand Down Expand Up @@ -952,6 +962,7 @@ - (bool) playAtTime:(NSTimeInterval) time
(void)time;

[player stop];
[player prepare];
[player seekToMsec:(int32_t)(currentTime * 1000)];
[self _updateVolume];
[player setLooping:(-1 == numberOfLoops) ? YES : NO];
Expand Down