fix audio playback, continious scroll, ajax request user agent

This commit is contained in:
Jonas Heinrich 2020-10-18 11:38:10 +02:00
parent d100c5d9a4
commit 0bd0e8cad3
4 changed files with 43 additions and 16 deletions

View File

@ -16,6 +16,9 @@
<dependencies> <dependencies>
<nextcloud min-version="19" max-version="20"/> <nextcloud min-version="19" max-version="20"/>
</dependencies> </dependencies>
<commands>
<command>OCA\Radio\Command\Search</command>
</commands>
<navigations> <navigations>
<navigation> <navigation>
<name>Radio</name> <name>Radio</name>

View File

@ -6,7 +6,9 @@
<Breadcrumb title="Home" href="/" /> <Breadcrumb title="Home" href="/" />
<Breadcrumb title="Top" href="/Top" /> <Breadcrumb title="Top" href="/Top" />
</Breadcrumbs> </Breadcrumbs>
<Table :station-data="tableData" /> <Table
:station-data="tableData"
@doPlay="doPlay" />
</AppContent> </AppContent>
</Content> </Content>
</template> </template>
@ -20,6 +22,8 @@ import Navigation from './Navigation'
import Table from './Table' import Table from './Table'
import { Howl } from 'howler' import { Howl } from 'howler'
let audioPlayer = null
export default { export default {
name: 'Main', name: 'Main',
components: { components: {
@ -37,26 +41,31 @@ export default {
mounted() { mounted() {
this.loadStations() this.loadStations()
this.scroll() this.scroll()
this.play()
}, },
methods: { methods: {
play() { doPlay(station) {
const sound = new Howl({ if (audioPlayer !== null) {
src: ['http://stream.srg-ssr.ch/m/drsvirus/mp3_128'], audioPlayer.fade(100, 0, 500) // FIXME persistent volume state
audioPlayer.unload() // FIXME do unload after fadeout
}
audioPlayer = new Howl({
src: [station.url_resolved],
volume: 0,
}) })
sound.play() audioPlayer.play()
audioPlayer.fade(0, 100, 500) // FIXME persistent volume state
}, },
loadStations() { loadStations() {
const vm = this const vm = this
this.$jquery.ajax({ this.$jquery.getJSON('https://de1.api.radio-browser.info/json/stations/search',
type: 'POST', {
url: 'https://de1.api.radio-browser.info/json/stations/topclick', limit: 20,
data: '{ "limit": 20, "offset": 20 }', order: 'clickcount',
contentType: 'application/json', reverse: true,
dataType: 'json', offset: vm.offset,
'User-Agent': 'Nextcloud Radio/1.0.0', // FIXME global version
}) })
.done(function(data) { .done(function(data) {
console.log('new data')
vm.tableData = vm.tableData.concat(data) vm.tableData = vm.tableData.concat(data)
vm.offset += 20 vm.offset += 20
}) })

View File

@ -11,11 +11,11 @@
</thead> </thead>
<tbody v-if="stationData"> <tbody v-if="stationData">
<tr v-for="(station, idx) in stationData" :key="idx"> <tr v-for="(station, idx) in stationData" :key="idx">
<td> <td @click="doPlay">
<div class="stationIcon" <div class="stationIcon"
:style="{ backgroundImage: `url('${ station.favicon }')` }" /> :style="{ backgroundImage: `url('${ station.favicon }')` }" />
</td> </td>
<td class="filenameColumn"> <td class="filenameColumn" @click="doPlay(station)">
<span class="innernametext"> <span class="innernametext">
{{ station.name }} {{ station.name }}
</span> </span>
@ -51,6 +51,11 @@ export default {
default() { return [] }, default() { return [] },
}, },
}, },
methods: {
doPlay(station) {
this.$emit('doPlay', station)
},
},
} }
</script> </script>
@ -110,6 +115,11 @@ table {
td.filenameColumn .innernametext { td.filenameColumn .innernametext {
color: var(--color-main-text); color: var(--color-main-text);
text-overflow: ellipsis;
overflow: hidden;
position: relative;
vertical-align: top;
user-select: none;
} }
.stationIcon { .stationIcon {

View File

@ -35,5 +35,10 @@ Vue.prototype.$jquery = jquery
export default new Vue({ export default new Vue({
el: '#content', el: '#content',
router, router,
methods: {
doPlay() {
console.log('event handled!')
},
},
render: h => h(App), render: h => h(App),
}) })