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

framework/media, apps/examples: sync from ecode #6590

Open
wants to merge 2 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
27 changes: 21 additions & 6 deletions apps/examples/SoundPlayer/soundplayer_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class SoundPlayer : public MediaPlayerObserverInterface,
{
public:
SoundPlayer() : mNumContents(0), mPlayIndex(-1), mHasFocus(false), mSampleRate(DEFAULT_SAMPLERATE_TYPE), \
mPaused(false), mIsPlaying(false), mStopped(false), mTrackFinished(false), mVolume(DEFAULT_VOLUME) {};
mPaused(false), mIsPlaying(false), mStopped(false), mTrackFinished(false), mVolume(DEFAULT_VOLUME), mLooping(false) {};
~SoundPlayer() {};
bool init(char *argv[]);
bool init(int argc, char *argv[]);
player_result_t startPlayback(void);
bool checkTrackFinished(void);
void handleError(player_error_t error);
Expand Down Expand Up @@ -85,6 +85,7 @@ class SoundPlayer : public MediaPlayerObserverInterface,
bool mTrackFinished;
unsigned int mSampleRate;
uint8_t mVolume;
bool mLooping;
void loadContents(const char *path);
};

Expand Down Expand Up @@ -149,6 +150,7 @@ void SoundPlayer::handleError(player_error_t error)
if (mHasFocus) {
auto &focusManager = FocusManager::getFocusManager();
focusManager.abandonFocus(mFocusRequest);
mHasFocus = false;
}
mp.unprepare();
mp.destroy();
Expand Down Expand Up @@ -195,7 +197,7 @@ void SoundPlayer::onFocusChange(int focusChange)
printf("it was paused, just start playback now\n");
res = mp.start();
if (res != PLAYER_OK) {
printf("start failed res : %d\n", res);
printf("player start failed res : %d\n", res);
}
} else {
res = startPlayback();
Expand All @@ -219,7 +221,7 @@ void SoundPlayer::onFocusChange(int focusChange)
}
}

bool SoundPlayer::init(char *argv[])
bool SoundPlayer::init(int argc, char *argv[])
{
struct stat st;
int ret;
Expand Down Expand Up @@ -266,6 +268,10 @@ bool SoundPlayer::init(char *argv[])
mSampleRate = atoi(argv[3]);
mTrackFinished = false;

if (argc > 5 && strcmp(argv[5], "1") == 0) {
mLooping = true;
}

auto &focusManager = FocusManager::getFocusManager();
printf("mp : %x request focus!!\n", &mp);
focusManager.requestFocus(mFocusRequest);
Expand All @@ -284,12 +290,18 @@ player_result_t SoundPlayer::startPlayback(void)
source->setPcmFormat(DEFAULT_FORMAT_TYPE);
res = mp.setDataSource(std::move(source));
if (res != PLAYER_OK) {
handleError((player_error_t)res);
printf("set Data source failed. res : %d\n", res);
return res;
}

if (mLooping) {
mp.setLooping(true);
printf("Looping is set to true\n");
}
res = mp.prepare();
if (res != PLAYER_OK) {
handleError((player_error_t)res);
printf("prepare failed res : %d\n", res);
return res;
}
Expand Down Expand Up @@ -384,11 +396,13 @@ int soundplayer_main(int argc, char *argv[])
auto player = std::shared_ptr<SoundPlayer>(new SoundPlayer());
printf("cur SoundPlayer : %x\n", &player);

if (argc != 5) {
if (argc != 6 && argc != 5) {
printf("invalid input\n");
printf("Usage : soundplayer [contents path] [volume] [sample rate] [stream policy] [looping]\n");
printf("looping argument is optional\n");
return -1;
}
if (!player->init(argv)) {
if (!player->init(argc, argv)) {
return -1;
}

Expand All @@ -401,3 +415,4 @@ int soundplayer_main(int argc, char *argv[])
return 0;
}
}

Loading