void UrlAudioPlayer::setLoop(bool isLoop) { _isLoop = isLoop; SLboolean loopEnable = _isLoop ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE; SLresult r = (*_seekItf)->SetLoop(_seekItf, loopEnable, 0, SL_TIME_UNKNOWN); SL_RETURN_IF_FAILED(r, "UrlAudioPlayer::setLoop %d failed", _isLoop ? 1 : 0); }
void UrlAudioPlayer::setVolume(float volume) { _volume = volume; int dbVolume = 2000 * log10(volume); if (dbVolume < SL_MILLIBEL_MIN) { dbVolume = SL_MILLIBEL_MIN; } SLresult r = (*_volumeItf)->SetVolumeLevel(_volumeItf, dbVolume); SL_RETURN_IF_FAILED(r, "UrlAudioPlayer::setVolume %d failed", dbVolume); }
void UrlAudioPlayer::play() { if (_state == State::INITIALIZED || _state == State::PAUSED) { SLresult r = (*_playItf)->SetPlayState(_playItf, SL_PLAYSTATE_PLAYING); SL_RETURN_IF_FAILED(r, "UrlAudioPlayer::play failed"); setState(State::PLAYING); } else { ALOGW("UrlAudioPlayer (%p, state:%d) isn't paused or initialized, could not invoke play!", this, static_cast<int>(_state)); } }
void UrlAudioPlayer::pause() { if (_state == State::PLAYING) { SLresult r = (*_playItf)->SetPlayState(_playItf, SL_PLAYSTATE_PAUSED); SL_RETURN_IF_FAILED(r, "UrlAudioPlayer::pause failed"); setState(State::PAUSED); } else { ALOGW("UrlAudioPlayer (%p, state:%d) isn't playing, could not invoke pause!", this, static_cast<int>(_state)); } }
void UrlAudioPlayer::resume() { if (_state == State::PAUSED) { SLresult r = (*_playItf)->SetPlayState(_playItf, SL_PLAYSTATE_PLAYING); SL_RETURN_IF_FAILED(r, "UrlAudioPlayer::resume failed"); setState(State::PLAYING); } else { ALOGW("UrlAudioPlayer (%p, state:%d) isn't paused, could not invoke resume!", this, _state); } }
void UrlAudioPlayer::stop() { ALOGV("UrlAudioPlayer::stop (%p, %d)", this, getId()); SLresult r = (*_playItf)->SetPlayState(_playItf, SL_PLAYSTATE_STOPPED); SL_RETURN_IF_FAILED(r, "UrlAudioPlayer::stop failed"); if (_state == State::PLAYING || _state == State::PAUSED) { setLoop(false); setState(State::STOPPED); if (_playEventCallback != nullptr) { _playEventCallback(State::STOPPED); } destroy(); delete this; } else { ALOGW("UrlAudioPlayer (%p, state:%d) isn't playing or paused, could not invoke stop!", this, static_cast<int>(_state)); } }
void PcmAudioService::resume() { SLresult r = (*_playItf)->SetPlayState(_playItf, SL_PLAYSTATE_PLAYING); SL_RETURN_IF_FAILED(r, "PcmAudioService::resume failed"); }