Skip to content

Commit

Permalink
+ HTML fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
fritx committed Apr 28, 2016
1 parent 460edc5 commit 7359bab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
59 changes: 34 additions & 25 deletions Apps/SoundApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,41 @@ export default class MainView extends Component {
}

playSound() {
// todo: download
console.log('playSOund')
const url = 'http://downdb.51voa.com/201604/fusion-reactor-still-in-works.mp3'
const file = RNFS.DocumentDirectoryPath + '/fusion.mp3'
console.log(url)
console.log(' => ', file)
RNFS.downloadFile(url, file, (d) => {
console.log('downloading', d)
}, (d) => {
// console.log(`${d.bytesWritten} / ${d.contentLength}`)
})
.then(() => {
console.log('downloaded')
// todo: fetch html
// https://github.com/fritx/51voa-cli
const url = 'http://www.51voa.com/VOA_Standard_English/from-golf-range-to-free-range-69274.html'
console.log('fetching...', url)
fetch(url)
.then((response) => response.text())
.then((html) => {
// const url = 'http://downdb.51voa.com/201604/fusion-reactor-still-in-works.mp3'
// const file = RNFS.DocumentDirectoryPath + '/fusion.mp3'
const part = html.match(/Player\("(.+?)"\);/)[1]
const url = `http://downdb.51voa.com${part}`
const file = RNFS.DocumentDirectoryPath + '/golf.mp3'
console.log(url)
console.log(' => ', file)
RNFS.downloadFile(url, file, (d) => {
console.log('downloading', d)
}, (d) => {
// console.log(`${d.bytesWritten} / ${d.contentLength}`)
})
.then(() => {
console.log('downloaded')

// fixme: https://github.com/zmxv/react-native-sound/issues/27
// var s = new Sound('advertising.mp3', Sound.MAIN_BUNDLE, (e) => {
// var s = new Sound(file + '.aa', Sound.MAIN_BUNDLE, (e) => {
var s = new Sound(file, '/', (e) => { // hack
if (e) {
console.log('error', e);
} else {
console.log('duration', s.getDuration());
s.play();
}
});
})
// fixme: https://github.com/zmxv/react-native-sound/issues/27
// var s = new Sound('advertising.mp3', Sound.MAIN_BUNDLE, (e) => {
// var s = new Sound(file + '.aa', Sound.MAIN_BUNDLE, (e) => {
var s = new Sound(file, '/', (e) => { // hack
if (e) {
console.log('error', e);
} else {
console.log('duration', s.getDuration());
s.play();
}
});
})
})
}
}

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $ npm run android
- [x] Movie App [docs/tutorial](https://facebook.github.io/react-native/docs/tutorial.html)
- [x] Sound App [react-native-sound](https://github.com/zmxv/react-native-sound)
- [x] Fs & Download [react-native-fs](https://github.com/zmxv/react-native-fs)
- [x] HTML Fetch [docs/network#fetch](https://facebook.github.io/react-native/docs/network.html#fetch)
- [ ] ...


Expand Down

0 comments on commit 7359bab

Please sign in to comment.