Skip to content

Commit

Permalink
Minimum viable version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob37 committed Sep 19, 2021
1 parent 70d057b commit 111e0a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
17 changes: 12 additions & 5 deletions components/AudioPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AudioPlayer {
* @param {[string,string][]} audioPathPairs
*/
load(audioPathPairs) {
for (const [english, chinese] of audioPathPairs) {
for (const [chinese, english] of audioPathPairs) {
const audioPair = new AudioPair(english, chinese)
this.audio.push(audioPair)
}
Expand All @@ -73,7 +73,7 @@ class AudioPlayer {
// console.log('found pair', pair);
this.currentlyPlayingPair = pair

playAudio(pair.chinesePath)
playAudio(pair.englishPath, () => { this.playEvent() })

// this.playPath(pair.englishAudio);
// this.currentlyPlayingPair.englishAudio.play((success) => {
Expand Down Expand Up @@ -103,25 +103,32 @@ class AudioPlayer {
}

playEvent() {
console.log('--- play event triggered ---')
if (!this.isPlaying) {
console.log("Not playing, returning!")
return
}

if (this.audioState == AudioState.playing_english) {
console.log('play random')
this.playRandom()
this.audioState = AudioState.english_pause
} else if (this.audioState == AudioState.english_pause) {
console.log('english_pause')
this.playPause(this.delay)
this.audioState = AudioState.playing_chinese
} else if (this.audioState == AudioState.playing_chinese) {
console.log('playing_chinese')
const currAudio = this.currentlyPlayingPair
// this.currentlyPlayingPair = null;
currAudio.chineseAudio.play((_success) => {
this.playEvent()
})
playAudio(currAudio.chinesePath, () => { this.playEvent() })

// currAudio.chineseAudio.play((_success) => {
// this.playEvent()
// })
this.audioState = AudioState.chinese_pause
} else if (this.audioState == AudioState.chinese_pause) {
console.log('chinese_pause')
this.playPause(this.delay)
this.audioState = AudioState.playing_english
} else {
Expand Down
16 changes: 12 additions & 4 deletions src/views/card/audiocard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import Amplify, { Storage } from "aws-amplify";
import Sound from "react-native-sound";


const playAudio = async (key) => {
/**
* @param {string} key
* @param {() => void|null} [callback=null]
*/
const playAudio = async (key, callback=null) => {

// console.log('Attempting to play', key);

Expand All @@ -18,7 +22,11 @@ const playAudio = async (key) => {
if (e) {
console.log('error loading track:', e)
} else {
track.play()
if (callback != null) {
track.play(callback)
} else {
track.play()
}
}
})
}
Expand Down Expand Up @@ -52,13 +60,13 @@ const AudioCard = (param) => {
</TouchableOpacity>
</View>

<TouchableOpacity onPress={() => {
{/* <TouchableOpacity onPress={() => {
removeTrack(param.chineseKey, param.englishKey).then(param.endAction)
}}>
<View>
<Text style={{ color: 'gray', fontWeight: 'bold', fontSize: 24 }}>X</Text>
</View>
</TouchableOpacity>
</TouchableOpacity> */}
</View>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const AudioFooter = (param) => {
]}>
<FooterButton onPress={() => { audioPlayer.play() }}>Play</FooterButton>
<FooterButton onPress={() => { audioPlayer.playRandom() }}>Random</FooterButton>
<FooterButton onPress={audioPlayer.stop}>Stop</FooterButton>
<FooterButton onPress={() => { audioPlayer.stop() }}>Stop</FooterButton>
<FooterButton onPress={param.backToMenu}>Back</FooterButton>
</View>
)
Expand Down

0 comments on commit 111e0a2

Please sign in to comment.