added search and play from search
This commit is contained in:
parent
56a475d904
commit
60f9f83c09
2 changed files with 102 additions and 29 deletions
|
@ -106,7 +106,12 @@
|
|||
<div class="app-sidebar-header">
|
||||
<div class="search-input-container">
|
||||
<div class="search-input--icon"></div>
|
||||
<input type="search" placeholder="Search..." class="search-input">
|
||||
<input type="search"
|
||||
@click="showSearch()"
|
||||
@change="showSearch();searchQuery()"
|
||||
placeholder="Search..."
|
||||
v-model="search.term"
|
||||
class="search-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="app-sidebar-content">
|
||||
|
@ -142,6 +147,8 @@
|
|||
</div>
|
||||
</div>
|
||||
<div id="app-content">
|
||||
<!-- Browse -->
|
||||
<template v-if="page == 'browse'">
|
||||
<button class="md-btn md-btn-primary" @click="init()">Start MusicKit</button>
|
||||
<br>
|
||||
<template v-if="mk.nowPlayingItem">
|
||||
|
@ -172,6 +179,49 @@
|
|||
<button class="md-btn" @click="drawertest = !drawertest">Toggle Drawer</button>
|
||||
<button class="md-btn">Button</button>
|
||||
<button class="md-btn md-btn-primary">Button</button>
|
||||
</template>
|
||||
<!-- Search -->
|
||||
<template v-if="page == 'search'">
|
||||
<h1 class="header-text">{{ search.term }}</h1>
|
||||
<template v-if="search.results['meta']">
|
||||
<template v-if="search.results.songs">
|
||||
<h3>Songs</h3>
|
||||
<button
|
||||
@click="playMediaItemById(item.id, item.type)"
|
||||
v-for="item in search.results.songs.data">
|
||||
<b>{{ item.attributes.name }}</b>
|
||||
<br>
|
||||
{{ item.attributes.artistName }}
|
||||
</button>
|
||||
</template>
|
||||
<template v-if="search.results.songs">
|
||||
<h3>Albums</h3>
|
||||
<button
|
||||
@click="playMediaItemById(item.id, item.type)"
|
||||
v-for="item in search.results.albums.data">
|
||||
<b>{{ item.attributes.name }}</b>
|
||||
<br>
|
||||
{{ item.attributes.artistName }}
|
||||
</button>
|
||||
</template>
|
||||
<template v-if="search.results.songs">
|
||||
<h3>Artists</h3>
|
||||
<button
|
||||
@click="playMediaItemById(item.id, item.type)"
|
||||
v-for="item in search.results.artists.data">
|
||||
{{ item.attributes.name }}
|
||||
</button>
|
||||
</template>
|
||||
<template v-if="search.results.songs">
|
||||
<h3>Playlists</h3>
|
||||
<button
|
||||
@click="playMediaItemById(item.id, item.type)"
|
||||
v-for="item in search.results.playlists.data">
|
||||
{{ item.attributes.name }}
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
<div class="app-drawer" v-if="drawertest">
|
||||
|
||||
|
|
|
@ -3,7 +3,12 @@ var app = new Vue({
|
|||
data: {
|
||||
drawertest: false,
|
||||
mk: {},
|
||||
quickPlayQuery: ""
|
||||
quickPlayQuery: "",
|
||||
search: {
|
||||
term: "",
|
||||
results: {}
|
||||
},
|
||||
page: "browse"
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
|
@ -11,6 +16,24 @@ var app = new Vue({
|
|||
this.mk.authorize()
|
||||
this.$forceUpdate()
|
||||
},
|
||||
showSearch() {
|
||||
this.page = "search"
|
||||
},
|
||||
playMediaItemById(id, kind) {
|
||||
this.mk.setQueue({ [kind]: [id] }).then(function (queue) {
|
||||
MusicKit.getInstance().play()
|
||||
})
|
||||
},
|
||||
searchQuery() {
|
||||
let self = this
|
||||
this.mk.api.search(this.search.term,
|
||||
{
|
||||
types: "songs,artists,albums,playlists",
|
||||
limit: 32
|
||||
}).then(function(results) {
|
||||
self.search.results = results
|
||||
})
|
||||
},
|
||||
mkReady() {
|
||||
if(this.mk["nowPlayingItem"]) {
|
||||
return true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue