Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
missing segment fix (#467)
Browse files Browse the repository at this point in the history
* handle when no segment

return state when segments isnt defined

ensure to target mp3 audio

ensure to target mp3 audio

revert audio.mp3

multi-purpose function

revert audio.mp3

* multi-purpose function

update travis to node 6, use node_modules travis says it cannot find modules(eslint, karma)

ditto

* fix unit tests

fix unit tests
  • Loading branch information
thabti authored and mmahalwy committed Aug 29, 2016
1 parent 31bac53 commit d06fdd3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: false
language: node_js
env: TEST_SUITE=unit
node_js:
- "5.6.0"
- "6.3.0"
cache:
directories:
- node_modules
Expand Down
2 changes: 2 additions & 0 deletions src/components/Audioplayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export class Audioplayer extends Component {

renderPreviousButton() {
const { currentAyah, files } = this.props;
if (!files) return false;
const index = Object.keys(files).findIndex(id => id === currentAyah);

return (
Expand All @@ -358,6 +359,7 @@ export class Audioplayer extends Component {

renderNextButton() {
const { surah, currentAyah } = this.props;
if (!surah) return false;
const isEnd = surah.ayat === parseInt(currentAyah.split(':')[1], 10);

return (
Expand Down
6 changes: 4 additions & 2 deletions src/components/TopOptions/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ describe("<TopOptions />", () => {
};

const actions = {
setOption: () => {},
toggleReadingMode: () => {}
options: {
setOption: () => {},
toggleReadingMode: () => {}
}
};

const component = shallow(<TopOptions
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/buildAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ export function buildAudioForAyah(audio) {
if (audio.url) {
scopedAudio.src = audio.url;
segments = audio.encryptedSegments;
return { audio: scopedAudio, segments };
}

if (audio.mp3) {
scopedAudio.src = audio.mp3.url;
segments = audio.mp3.encryptedSegments;
return { audio: scopedAudio, segments };
}

return { audio: scopedAudio, segments };
Expand Down
11 changes: 5 additions & 6 deletions src/redux/modules/audioplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ export default function reducer(state = initialState, action = {}) {
}
case SET_CURRENT_WORD: {
if (!action.word) return state;

const [surahId, ayahNum, word] = action.word.split(':');
let currentTime = null;

if (state.files[surahId][`${surahId}:${ayahNum}`] === state.currentFile) {
const [surahId, ayahNum, word] = action.word.split(':');
const nextId = `${surahId}:${ayahNum}`;
if (!state.segments[surahId][nextId]) return state;
if (state.files[surahId][nextId] === state.currentFile) {
// When the files are the same, set the current time to that word
currentTime = state.segments[surahId][`${surahId}:${ayahNum}`].words[word].startTime;
currentTime = state.segments[surahId][nextId].words[word].startTime;
state.currentFile.currentTime = currentTime; // eslint-disable-line no-param-reassign

return {
Expand All @@ -256,7 +256,6 @@ export default function reducer(state = initialState, action = {}) {
}

// When the files are not the same.
const nextId = `${surahId}:${ayahNum}`;
const currentFile = state.files[surahId][nextId];
const segment = buildSegments(state.segments[surahId][nextId]);
currentTime = segment.words[word].startTime;
Expand Down

0 comments on commit d06fdd3

Please sign in to comment.