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="app-sidebar-header">
|
||||||
<div class="search-input-container">
|
<div class="search-input-container">
|
||||||
<div class="search-input--icon"></div>
|
<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>
|
</div>
|
||||||
<div class="app-sidebar-content">
|
<div class="app-sidebar-content">
|
||||||
|
@ -142,6 +147,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="app-content">
|
<div id="app-content">
|
||||||
|
<!-- Browse -->
|
||||||
|
<template v-if="page == 'browse'">
|
||||||
<button class="md-btn md-btn-primary" @click="init()">Start MusicKit</button>
|
<button class="md-btn md-btn-primary" @click="init()">Start MusicKit</button>
|
||||||
<br>
|
<br>
|
||||||
<template v-if="mk.nowPlayingItem">
|
<template v-if="mk.nowPlayingItem">
|
||||||
|
@ -172,6 +179,49 @@
|
||||||
<button class="md-btn" @click="drawertest = !drawertest">Toggle Drawer</button>
|
<button class="md-btn" @click="drawertest = !drawertest">Toggle Drawer</button>
|
||||||
<button class="md-btn">Button</button>
|
<button class="md-btn">Button</button>
|
||||||
<button class="md-btn md-btn-primary">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>
|
||||||
<div class="app-drawer" v-if="drawertest">
|
<div class="app-drawer" v-if="drawertest">
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,12 @@ var app = new Vue({
|
||||||
data: {
|
data: {
|
||||||
drawertest: false,
|
drawertest: false,
|
||||||
mk: {},
|
mk: {},
|
||||||
quickPlayQuery: ""
|
quickPlayQuery: "",
|
||||||
|
search: {
|
||||||
|
term: "",
|
||||||
|
results: {}
|
||||||
|
},
|
||||||
|
page: "browse"
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
|
@ -11,6 +16,24 @@ var app = new Vue({
|
||||||
this.mk.authorize()
|
this.mk.authorize()
|
||||||
this.$forceUpdate()
|
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() {
|
mkReady() {
|
||||||
if(this.mk["nowPlayingItem"]) {
|
if(this.mk["nowPlayingItem"]) {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue