From 514aa0a69fe92513bb78f475c5ad45c7728e824f Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 16 Dec 2015 14:59:17 -0800 Subject: [PATCH] Add iOS implementations for MediaPlayer volume and looping setters --- sky/services/media/ios/media_player_impl.h | 2 ++ sky/services/media/ios/media_player_impl.mm | 26 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/sky/services/media/ios/media_player_impl.h b/sky/services/media/ios/media_player_impl.h index 3ceaba71afc..59a7d111e74 100644 --- a/sky/services/media/ios/media_player_impl.h +++ b/sky/services/media/ios/media_player_impl.h @@ -32,6 +32,8 @@ class MediaPlayerImpl : public ::media::MediaPlayer { void Start() override; void Pause() override; void SeekTo(uint32_t msec) override; + void SetVolume(float volume) override; + void SetLooping(bool looping) override; private: mojo::StrongBinding<::media::MediaPlayer> binding_; diff --git a/sky/services/media/ios/media_player_impl.mm b/sky/services/media/ios/media_player_impl.mm index 0250a93e436..71547cacc2f 100644 --- a/sky/services/media/ios/media_player_impl.mm +++ b/sky/services/media/ios/media_player_impl.mm @@ -17,6 +17,8 @@ - (BOOL)play; - (void)pause; - (BOOL)seekTo:(NSTimeInterval)interval; +- (void)setVolume:(double)volume; +- (void)setLooping:(BOOL)loop; + (NSString*)temporaryFilePath; @@ -58,6 +60,22 @@ return [_player playAtTime:_player.deviceCurrentTime + interval]; } +- (void)setVolume:(double)volume { + if (volume > 1.0) { + volume = 1.0; + } + + if (volume < 0.0) { + volume = 0.0; + } + + _player.volume = volume; +} + +- (void)setLooping:(BOOL)shouldLoop { + _player.numberOfLoops = shouldLoop ? -1 : 0; +} + + (NSString*)temporaryFilePath { char temp[256] = {0}; @@ -136,6 +154,14 @@ void MediaPlayerImpl::reset() { audio_client_ = nullptr; } +void MediaPlayerImpl::SetVolume(float volume) { + [audio_client_ setVolume:volume]; +} + +void MediaPlayerImpl::SetLooping(bool looping) { + [audio_client_ setLooping:looping]; +} + void MediaPlayerFactory::Create( mojo::ApplicationConnection* connection, mojo::InterfaceRequest<::media::MediaPlayer> request) {