aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_musiconhold.c
diff options
context:
space:
mode:
authorpabelanger <pabelanger@f38db490-d61c-443f-a65b-d21fe96a405b>2010-06-14 21:31:59 +0000
committerpabelanger <pabelanger@f38db490-d61c-443f-a65b-d21fe96a405b>2010-06-14 21:31:59 +0000
commit4c00c42c8e687a2d35922373bf15165b6149a233 (patch)
treeac1ea4bd56c6b54170b07f16f361d27d616bbd56 /res/res_musiconhold.c
parent8f61931fe52b5ef12d2997d04509a48d79787a25 (diff)
Properly play first file in sort list.
When using sort=alpha we would always skip the first file in the list first time through. We now check for that properly. (closes issue #17470) Reported by: pabelanger Patches: sort.aplha.patch uploaded by pabelanger (license 224) Tested by: lmadsen Review: https://reviewboard.asterisk.org/r/703/ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@270331 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_musiconhold.c')
-rw-r--r--res/res_musiconhold.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index cb50b4c58..271779461 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -225,16 +225,20 @@ static int ast_moh_files_next(struct ast_channel *chan)
return -1;
}
- /* If a specific file has been saved confirm it still exists and that it is still valid */
- if (state->save_pos >= 0 && state->save_pos < state->class->total_files && state->class->filearray[state->save_pos] == state->save_pos_filename) {
+ if (state->pos == 0 && state->save_pos_filename == NULL) {
+ /* First time so lets play the file. */
+ state->save_pos = -1;
+ } else if (state->save_pos >= 0 && state->save_pos < state->class->total_files && state->class->filearray[state->save_pos] == state->save_pos_filename) {
+ /* If a specific file has been saved confirm it still exists and that it is still valid */
state->pos = state->save_pos;
state->save_pos = -1;
} else if (ast_test_flag(state->class, MOH_RANDOMIZE)) {
/* Get a random file and ensure we can open it */
for (tries = 0; tries < 20; tries++) {
state->pos = ast_random() % state->class->total_files;
- if (ast_fileexists(state->class->filearray[state->pos], NULL, NULL) > 0)
+ if (ast_fileexists(state->class->filearray[state->pos], NULL, NULL) > 0) {
break;
+ }
}
state->save_pos = -1;
state->samples = 0;
@@ -259,8 +263,9 @@ static int ast_moh_files_next(struct ast_channel *chan)
if (option_debug)
ast_log(LOG_DEBUG, "%s Opened file %d '%s'\n", chan->name, state->pos, state->class->filearray[state->pos]);
- if (state->samples)
+ if (state->samples) {
ast_seekstream(chan->stream, state->samples, SEEK_SET);
+ }
return 0;
}