From 43fc2616560257f043bd5d366feae794fc748729 Mon Sep 17 00:00:00 2001 From: rubenaeg Date: Mon, 2 Mar 2020 15:05:47 +0100 Subject: [PATCH 1/6] :ok_hand: Adjust Bixby AudioPlayer Functionality --- docs/platforms/samsung-bixby/audioplayer.md | 49 ++++++++++++++++--- .../src/modules/BixbyAudioPlayer.ts | 7 ++- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/docs/platforms/samsung-bixby/audioplayer.md b/docs/platforms/samsung-bixby/audioplayer.md index eb354b5874..987db0af04 100644 --- a/docs/platforms/samsung-bixby/audioplayer.md +++ b/docs/platforms/samsung-bixby/audioplayer.md @@ -6,6 +6,7 @@ Learn more about how to use the Bixby AudioPlayer functionality. - [Prerequisites](#prerequisites) - [Usage](#usage) - [Play](#play) + - [Enqueue](#enqueue) - [Meta Data](#meta-data) ## Introduction @@ -133,10 +134,45 @@ this.$bixbyCapsule.$audioPlayer.play({ }); // Alternative function headers +this.$bixbyCapsule.$audioPlayer.setAudioStream({ url, format }); + +// @language=typescript + +// Play audio file from url with specified format (e.g. audio/mp3) +this.$bixbyCapsule!.$audioPlayer!.play({ url, format }); + +// You can optionally specify a token and an offset in ms +this.$bixbyCapsule!.$audioPlayer!.play({ + url, + format, + token, + offsetInMilliseconds +}); + +// Alternative function headers +this.$bixbyCapsule!.$audioPlayer!.setAudioStream({ url, format }); +``` + +### Enqueue + +```javascript +// @language=javascript + +// Enqueue an audio stream into an existing playlist. this.$bixbyCapsule.$audioPlayer.enqueue({ url, format }); + +// You can optionally specify a token and an offset in ms. +this.$bixbyCapsule.$audioPlayer.enqueue({ + url, + format, + token, + offsetInMilliseconds +}); + +// Alternative function headers this.$bixbyCapsule.$audioPlayer.addAudioStream({ url, format }); -// You can also add an array of audio items +// You can also add an array of audio items. this.$bixbyCapsule.$audioPlayer.addAudioStreams([ { url1, format }, { url2, format } @@ -144,11 +180,11 @@ this.$bixbyCapsule.$audioPlayer.addAudioStreams([ // @language=typescript -// Play audio file from url with specified format (e.g. audio/mp3) -this.$bixbyCapsule!.$audioPlayer!.play({ url, format }); +// Enqueue an audio stream into an existing playlist. +this.$bixbyCapsule!.$audioPlayer!.enqueue({ url, format }); -// You can optionally specify a token and an offset in ms -this.$bixbyCapsule!.$audioPlayer!.play({ +// You can optionally specify a token and an offset in ms. +this.$bixbyCapsule!.$audioPlayer!.enqueue({ url, format, token, @@ -156,10 +192,9 @@ this.$bixbyCapsule!.$audioPlayer!.play({ }); // Alternative function headers -this.$bixbyCapsule!.$audioPlayer!.enqueue({ url, format }); this.$bixbyCapsule!.$audioPlayer!.addAudioStream({ url, format }); -// You can also add an array of audio items +// You can also add an array of audio items. this.$bixbyCapsule!.$audioPlayer!.addAudioStreams([ { url1, format }, { url2, format } diff --git a/jovo-platforms/jovo-platform-bixby/src/modules/BixbyAudioPlayer.ts b/jovo-platforms/jovo-platform-bixby/src/modules/BixbyAudioPlayer.ts index ad142ac3d0..2d545a76c0 100644 --- a/jovo-platforms/jovo-platform-bixby/src/modules/BixbyAudioPlayer.ts +++ b/jovo-platforms/jovo-platform-bixby/src/modules/BixbyAudioPlayer.ts @@ -104,7 +104,7 @@ export class BixbyAudioPlayer { } play(item: Stream) { - this.addAudioStream(item); + this.setAudioStream(item); return this; } @@ -129,6 +129,11 @@ export class BixbyAudioPlayer { return this; } + setAudioStream(item: Stream) { + this.audioItem.stream = [item]; + return this; + } + // -- Helper functions for AudioItem MetaData -- setId(id: string) { this.audioItem.id = id; From 8c9eadcbc6325d04610c0a27525b9be6dc9e8f59 Mon Sep 17 00:00:00 2001 From: rubenaeg Date: Mon, 2 Mar 2020 16:13:40 +0100 Subject: [PATCH 2/6] :ok_hand: Adjust Bixby AudioPlayer Functionality --- .../src/modules/BixbyAudioPlayer.ts | 95 ++++++++----------- 1 file changed, 37 insertions(+), 58 deletions(-) diff --git a/jovo-platforms/jovo-platform-bixby/src/modules/BixbyAudioPlayer.ts b/jovo-platforms/jovo-platform-bixby/src/modules/BixbyAudioPlayer.ts index 2d545a76c0..a382d06f8f 100644 --- a/jovo-platforms/jovo-platform-bixby/src/modules/BixbyAudioPlayer.ts +++ b/jovo-platforms/jovo-platform-bixby/src/modules/BixbyAudioPlayer.ts @@ -17,12 +17,12 @@ export interface Stream { } export interface AudioInfo { - id: string; - stream?: Stream[]; - title: string; + id?: string; + stream: Stream[]; + title?: string; subtitle?: string; - artist: string; - albumArtUrl: string; + artist?: string; + albumArtUrl?: string; duration?: number; albumName?: string; } @@ -59,7 +59,7 @@ export class BixbyAudioPlayerPlugin implements Plugin { capsule.$response = new BixbyResponse(); } - if (capsule.$audioPlayer && capsule.$audioPlayer.audioItem.stream) { + if (capsule.$audioPlayer && capsule.$audioPlayer.audioItem.length > 0) { _set(capsule.$response, '_JOVO_AUDIO_', capsule.$audioPlayer); } } @@ -67,13 +67,8 @@ export class BixbyAudioPlayerPlugin implements Plugin { export class BixbyAudioPlayer { readonly category = 'MUSIC'; - audioItem: AudioInfo = { - id: '', - title: '', - artist: '', - albumArtUrl: '', - }; - displayName = ''; + audioItem: AudioInfo[] = []; + displayName = 'Jovo AudioStream'; doNotWaitForTTS = false; repeatMode?: RepeatMode; startAudioItemIndex?: number; @@ -103,75 +98,59 @@ export class BixbyAudioPlayer { return this; } - play(item: Stream) { + play(item: AudioInfo) { this.setAudioStream(item); return this; } - enqueue(item: Stream) { + enqueue(item: AudioInfo) { this.addAudioStream(item); return this; } - addAudioStream(item: Stream) { - if (!this.audioItem.stream) { - this.audioItem.stream = []; + addAudioStream(item: AudioInfo) { + // Create default values for obligatory properties. + if (!item.title) { + item.title = 'AudioStream'; } - this.audioItem.stream.push(item); - return this; - } - addAudioStreams(items: Stream[]) { - if (!this.audioItem.stream) { - this.audioItem.stream = []; + if (!item.artist) { + item.artist = 'Bixby'; } - this.audioItem.stream.push(...items); - return this; - } - setAudioStream(item: Stream) { - this.audioItem.stream = [item]; - return this; - } + if (!item.id) { + item.id = Date.now().toString(); + } - // -- Helper functions for AudioItem MetaData -- - setId(id: string) { - this.audioItem.id = id; - return this; - } + if (!item.albumArtUrl) { + item.albumArtUrl = 'https://test.jpg'; + } - setTitle(title: string) { - this.audioItem.title = title; - return this; - } + if (item.stream) { + for (const audio of item.stream) { + if (!audio.format) { + audio.format = 'audio/mp3'; + } + } + } - setSubtitle(subtitle: string) { - this.audioItem.subtitle = subtitle; - return this; - } + this.audioItem.push(item); - setArtist(artist: string) { - this.audioItem.artist = artist; return this; } - setAlbumArt(url: string) { - this.audioItem.albumArtUrl = url; - return this; - } + addAudioStreams(items: AudioInfo[]) { + for (const item of items) { + this.addAudioStream(item); + } - setAlbumName(name: string) { - this.audioItem.albumName = name; return this; } - setDuration(duration: number) { - this.audioItem.duration = duration; - return this; - } + setAudioStream(item: AudioInfo) { + this.audioItem = []; + this.addAudioStream(item); - setMetaData(data: AudioInfo) { - Object.assign(this.audioItem, data); return this; } } From f20a7b2c1bebdccbd89ae8a7b00b6ee944b38bfa Mon Sep 17 00:00:00 2001 From: rubenaeg Date: Mon, 2 Mar 2020 16:36:54 +0100 Subject: [PATCH 3/6] :pencil: Adjust AudioPlayer Docs --- docs/platforms/samsung-bixby/audioplayer.md | 154 +++++++----------- .../src/modules/BixbyAudioPlayer.ts | 2 +- 2 files changed, 56 insertions(+), 100 deletions(-) diff --git a/docs/platforms/samsung-bixby/audioplayer.md b/docs/platforms/samsung-bixby/audioplayer.md index 987db0af04..23667a8c53 100644 --- a/docs/platforms/samsung-bixby/audioplayer.md +++ b/docs/platforms/samsung-bixby/audioplayer.md @@ -122,35 +122,43 @@ this.$bixbyCapsule!.$audioPlayer! ```javascript // @language=javascript -// Play audio file from url with specified format (e.g. audio/mp3) -this.$bixbyCapsule.$audioPlayer.play({ url, format }); +// Play a single audio file from url with specified format (e.g. audio/mp3) +this.$bixbyCapsule.$audioPlayer.play({ stream: [{ url }] }); -// You can optionally specify a token and an offset in ms +// You can optionally specify the following properties. If not given, default values will be used. this.$bixbyCapsule.$audioPlayer.play({ - url, - format, - token, - offsetInMilliseconds + id, + stream: [{ url, format }], + title, + subtitle, + artist, + albumArtUrl, + duration, + albumName }); // Alternative function headers -this.$bixbyCapsule.$audioPlayer.setAudioStream({ url, format }); +this.$bixbyCapsule.$audioPlayer.setAudioStream({ stream: [{ url }] }); // @language=typescript -// Play audio file from url with specified format (e.g. audio/mp3) -this.$bixbyCapsule!.$audioPlayer!.play({ url, format }); +// Play a single audio file from url with specified format (e.g. audio/mp3) +this.$bixbyCapsule!.$audioPlayer!.play({ stream: [{ url }] }); -// You can optionally specify a token and an offset in ms +// You can optionally specify the following properties. If not given, default values will be used. this.$bixbyCapsule!.$audioPlayer!.play({ - url, - format, - token, - offsetInMilliseconds + id, + stream: [{ url, format }], + title, + subtitle, + artist, + albumArtUrl, + duration, + albumName }); // Alternative function headers -this.$bixbyCapsule!.$audioPlayer!.setAudioStream({ url, format }); +this.$bixbyCapsule!.$audioPlayer!.setAudioStream({ stream: [{ url }] }); ``` ### Enqueue @@ -159,45 +167,53 @@ this.$bixbyCapsule!.$audioPlayer!.setAudioStream({ url, format }); // @language=javascript // Enqueue an audio stream into an existing playlist. -this.$bixbyCapsule.$audioPlayer.enqueue({ url, format }); +this.$bixbyCapsule.$audioPlayer.enqueue({ stream: [{ url }] }); -// You can optionally specify a token and an offset in ms. +// You can optionally specify the following properties. If not given, default values will be used. this.$bixbyCapsule.$audioPlayer.enqueue({ - url, - format, - token, - offsetInMilliseconds + id, + stream: [{ url, format }], + title, + subtitle, + artist, + albumArtUrl, + duration, + albumName }); // Alternative function headers -this.$bixbyCapsule.$audioPlayer.addAudioStream({ url, format }); +this.$bixbyCapsule.$audioPlayer.addAudioStream({ stream: [{ url }] }); // You can also add an array of audio items. this.$bixbyCapsule.$audioPlayer.addAudioStreams([ - { url1, format }, - { url2, format } + { stream: [{ url1 }] }, + { stream: [{ url2 }] }, ]); // @language=typescript // Enqueue an audio stream into an existing playlist. -this.$bixbyCapsule!.$audioPlayer!.enqueue({ url, format }); +this.$bixbyCapsule!.$audioPlayer!.enqueue({ stream: [{ url }] }); -// You can optionally specify a token and an offset in ms. +// You can optionally specify the following properties. If not given, default values will be used. this.$bixbyCapsule!.$audioPlayer!.enqueue({ - url, - format, - token, - offsetInMilliseconds + id, + stream: [{ url, format }], + title, + subtitle, + artist, + albumArtUrl, + duration, + albumName }); // Alternative function headers -this.$bixbyCapsule!.$audioPlayer!.addAudioStream({ url, format }); +this.$bixbyCapsule!.$audioPlayer!.addAudioStream({ stream: [{ url }] }); // You can also add an array of audio items. this.$bixbyCapsule!.$audioPlayer!.addAudioStreams([ - { url1, format }, - { url2, format } + { stream: [{ url1 }] }, + { stream: [{ url2 }] }, ]); ``` @@ -206,7 +222,7 @@ this.$bixbyCapsule!.$audioPlayer!.addAudioStreams([ ```javascript // @language=javascript -// Set the display name +// Set the display name. this.$bixbyCapsule.$audioPlayer.setDisplayName(displayName); // Set whether to wait for TTS to finish, before playing audio. Default is true. @@ -218,38 +234,8 @@ this.$bixbyCapsule.$audioPlayer.setDoNotWaitForTTS(true); // If you have multiple audio items in the queue, you can specify a starting index, on which audio file the audioplayer is going to start this.$bixbyCapsule.$audioPlayer.setStartAudioItemIndex(index); -// Sets an id for the audio item containing your audio streams -this.$bixbyCapsule.$audioPlayer.setId(id); - -// Sets a title for the audio item containing your audio streams -this.$bixbyCapsule.$audioPlayer.setTitle(title); - -// Sets subtitles for the audio item containing your audio streams -this.$bixbyCapsule.$audioPlayer.setSubtitle(subtitle); - -// Sets the artist for the audio item containing your audio streams -this.$bixbyCapsule.$audioPlayer.setArtist(artist); - -// Sets the album art for the audio item containing your audio streams -this.$bixbyCapsule.$audioPlayer.setAlbumArt(url); - -// Sets an album name for the audio item containing your audio streams -this.$bixbyCapsule.$audioPlayer.setAlbumName(name); - -// Sets a duration for the audio item containing your audio streams -this.$bixbyCapsule.$audioPlayer.setDuration(duration); - -// You can also choose to set the whole audio item with it's metadata and audio streams -this.$bixbyCapsule.$audioPlayer.setMetaData({ - albumArtUrl, - albumName, - artist, - duration, - id, - stream, - subtitle, - title, -}); +// Set a repeat mode for your playlist. Possible values include OFF, ALL and NONE. +this.$bixbyCapsule.$audioPlayer.setRepeatMode(mode); // @language=typescript @@ -265,38 +251,8 @@ this.$bixbyCapsule!.$audioPlayer!.setDoNotWaitForTTS(true); // If you have multiple audio items in the queue, you can specify a starting index, on which audio file the audioplayer is going to start this.$bixbyCapsule!.$audioPlayer!.setStartAudioItemIndex(index); -// Sets an id for the audio item containing your audio streams -this.$bixbyCapsule!.$audioPlayer!.setId(id); - -// Sets a title for the audio item containing your audio streams -this.$bixbyCapsule!.$audioPlayer!.setTitle(title); - -// Sets subtitles for the audio item containing your audio streams -this.$bixbyCapsule!.$audioPlayer!.setSubtitle(subtitle); - -// Sets the artist for the audio item containing your audio streams -this.$bixbyCapsule!.$audioPlayer!.setArtist(artist); - -// Sets the album art for the audio item containing your audio streams -this.$bixbyCapsule!.$audioPlayer!.setAlbumArt(url); - -// Sets an album name for the audio item containing your audio streams -this.$bixbyCapsule!.$audioPlayer!.setAlbumName(name); - -// Sets a duration for the audio item containing your audio streams -this.$bixbyCapsule!.$audioPlayer!.setDuration(duration); - -// You can also choose to set the whole audio item with it's metadata and audio streams -this.$bixbyCapsule!.$audioPlayer!.setMetaData({ - albumArtUrl, - albumName, - artist, - duration, - id, - stream, - subtitle, - title, -}); +// Set a repeat mode for your playlist. Possible values include OFF, ALL and NONE. +this.$bixbyCapsule!.$audioPlayer!.setRepeatMode(mode); ```