Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

Commit

Permalink
#50 fix audio in correct answer
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidborredom committed Jun 21, 2018
1 parent e7127c4 commit 7968520
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 44 deletions.
33 changes: 18 additions & 15 deletions app/component/correct.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class CorrectPanel extends Component {
}
componentWillMount() {

this.loadAudio();
//this.loadAudio();
}

componentDidUpdate(){

this.loadAudio();
//this.loadAudio();
}


Expand All @@ -51,9 +51,11 @@ class CorrectPanel extends Component {
<Text style={ styles.correctText }>{ this.props.question.english }</Text>
</View>

<TouchableHighlight onPress={() => this.playAudio(true) } style={ styles.correctAudio }>
<Icon name="volume-up" style={ styles.correctVolume }></Icon>
</TouchableHighlight>
{this.props.question.audio != '' &&
(<TouchableHighlight onPress={() => this.loadAudio() } style={ styles.correctAudio }>
<Icon name="volume-up" style={ styles.correctVolume }></Icon>
</TouchableHighlight>)
}
</View>
);

Expand All @@ -74,13 +76,13 @@ class CorrectPanel extends Component {
);
}

loadAudio(){
loadAudio(){
this.quizAudio = new Sound(this.props.question.audio, Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}

this.playAudio(true);
});
}

Expand All @@ -89,16 +91,17 @@ class CorrectPanel extends Component {
playDifferentAudio = this.currentAudio != this.props.question.id && this.props.format == 'audio';

if(playDifferentAudio || forcePlay){

this.currentAudio = this.props.question.id;

this.quizAudio.play((success) => {
if (!success) {
this.quizAudio.reset();
}

this.currentAudio = this.props.question.id;
this.quizAudio.stop(() => {
this.quizAudio.play((success) => {
if (!success) {
//this.quizAudio.reset();
}
});
});

}

}

stripSpace(val){
Expand Down
8 changes: 2 additions & 6 deletions app/component/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ class QuestionPanel extends Component {
if (error) {
return;
}
this.playAudio()
this.playAudio();


});
}

Expand All @@ -195,11 +194,8 @@ class QuestionPanel extends Component {
}
});
});



}


}

}
Expand Down
2 changes: 1 addition & 1 deletion app/screens/Quiz/quizBeforeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class QuizBeforeScreen extends Component {
const { navigation } = this.props;

this.param = {
type: navigation.getParam('type',null),
formatType: navigation.getParam('formatType',null),
title: navigation.getParam('title',null),
studyType: navigation.getParam('studyType',null),
img: navigation.getParam('img',null),
Expand Down
34 changes: 20 additions & 14 deletions app/screens/Quiz/quizFlash.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,24 @@ import {

<View style={[ styles.col12, styles.quizAnswerWrapper ]}>
<ScrollView>
<View style={ !timerRun && styles.blocker }></View>


{ !this.state.showCorrect ?
(<Quiz
question={ this.state.question }
answerOptions={ this.state.question.answerOption }
onAnswerSelected={ this.stopTimer }
displayFormat={ this.state.answerFormat }
format={ this.state.format }
styleFormat={ this.quizOptions.style }
timesUp={ this.state.timesUp }
/>) :
(
<View>
<View style={ !timerRun && styles.blocker }></View>

<Quiz
question={ this.state.question }
answerOptions={ this.state.question.answerOption }
onAnswerSelected={ this.stopTimer }
displayFormat={ this.state.answerFormat }
format={ this.state.format }
styleFormat={ this.quizOptions.style }
timesUp={ this.state.timesUp }
/>
</View>
) :
(<View>
<CorrectPanel
question={ this.state.question }
Expand Down Expand Up @@ -762,7 +768,7 @@ import {

// this.props.navigation.navigate('ScoreScreen',{
// index : this.state.index,
// typeQuiz : this.state.type,
// typeQuiz : this.initialParams.formatType,
// studyTitle : this.title
// });

Expand Down Expand Up @@ -846,7 +852,7 @@ import {

onTimesUp = (val) => {

if(this.state.type == 'Quiz'){
if(this.initialParams.formatType == 'Quiz'){
this.setState({
showCorrect:true,
});
Expand Down Expand Up @@ -888,8 +894,8 @@ import {
}

this.addScore(isCorrect);

if(this.state.type == 'Quiz' && this.showCorrect){
console.log(this.initialParams.formatType, this.showCorrect);
if(this.initialParams.formatType == 'Quiz' && this.showCorrect){
setTimeout(() => {

this.setState({
Expand Down
14 changes: 6 additions & 8 deletions app/styles/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,17 +544,15 @@ module.exports = StyleSheet.create({
width:(window.width/2.5) - 10,
},
quizLong:{
padding:5,
padding:10,
width: window.width - 30
},
quizGrammar:{
padding:5,
paddingLeft:10,
paddingRight:10,
padding:10,
width: window.width - 30
},
quizVocab:{
padding:5,
padding:10,
width: window.width - 30
},
quizBtnPress:{
Expand Down Expand Up @@ -619,8 +617,8 @@ module.exports = StyleSheet.create({
paddingBottom:20
},
quizAnswerWrapper:{
position:'relative',
height: window.height - 210,
position:'relative',
height: window.height - 290,
},
additionalInfo:{
fontSize:25,
Expand Down Expand Up @@ -716,7 +714,7 @@ module.exports = StyleSheet.create({
position:'absolute',
top:10,
right:10,
zIndex:10,
zIndex:20,
},
correctVolume:{
color:primaryColor,
Expand Down

0 comments on commit 7968520

Please sign in to comment.