Skip to content

Commit

Permalink
Merge pull request #688 from rubenaeg/master
Browse files Browse the repository at this point in the history
👌 Adjust Bixby AudioPlayer Functionality
  • Loading branch information
aswetlow authored Mar 2, 2020
2 parents a1c5262 + 80dd230 commit eb20952
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 146 deletions.
171 changes: 81 additions & 90 deletions docs/platforms/samsung-bixby/audioplayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,48 +122,98 @@ 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({ stream: { url } });

// @language=typescript

// Play a single audio file from url with specified format (e.g. audio/mp3)
this.$bixbyCapsule!.$audioPlayer!.play({ stream: { url } });

// You can optionally specify the following properties. If not given, default values will be used.
this.$bixbyCapsule!.$audioPlayer!.play({
id,
stream: { url, format },
title,
subtitle,
artist,
albumArtUrl,
duration,
albumName
});

// Alternative function headers
this.$bixbyCapsule!.$audioPlayer!.setAudioStream({ stream: { url } });
```

### Enqueue

```javascript
// @language=javascript

// Enqueue an audio stream into an existing playlist.
this.$bixbyCapsule.$audioPlayer.enqueue({ stream: { url } });

// You can optionally specify the following properties. If not given, default values will be used.
this.$bixbyCapsule.$audioPlayer.enqueue({
id,
stream: { url, format },
title,
subtitle,
artist,
albumArtUrl,
duration,
albumName
});

// Alternative function headers
this.$bixbyCapsule.$audioPlayer.enqueue({ url, format });
this.$bixbyCapsule.$audioPlayer.addAudioStream({ url, format });
this.$bixbyCapsule.$audioPlayer.addAudioStream({ stream: { url } });

// 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 }
{ stream: { url1 } },
{ stream: { url2 } },
]);

// @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({ stream: { url } });

// You can optionally specify a token and an offset in ms
this.$bixbyCapsule!.$audioPlayer!.play({
url,
format,
token,
offsetInMilliseconds
// You can optionally specify the following properties. If not given, default values will be used.
this.$bixbyCapsule!.$audioPlayer!.enqueue({
id,
stream: { url, format },
title,
subtitle,
artist,
albumArtUrl,
duration,
albumName
});

// Alternative function headers
this.$bixbyCapsule!.$audioPlayer!.enqueue({ url, format });
this.$bixbyCapsule!.$audioPlayer!.addAudioStream({ url, format });
this.$bixbyCapsule!.$audioPlayer!.addAudioStream({ stream: { url } });

// 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 }
{ stream: { url1 } },
{ stream: { url2 } },
]);
```

Expand All @@ -171,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.
Expand All @@ -183,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

Expand All @@ -230,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);
```

<!--[metadata]: {"description": "Learn more about how to use the Bixby AudioPlayer functionality.",
Expand Down
92 changes: 36 additions & 56 deletions jovo-platforms/jovo-platform-bixby/src/modules/BixbyAudioPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export type Format = '';

export interface Stream {
url: string;
format: string;
format?: string;
token?: string;
offsetInMilliseconds?: number;
}

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;
}
Expand Down Expand Up @@ -59,21 +59,16 @@ 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);
}
}
}

export class BixbyAudioPlayer {
readonly category = 'MUSIC';
audioItem: AudioInfo = {
id: '',
title: '',
artist: '',
albumArtUrl: '',
};
displayName = '';
audioItem: AudioInfo[] = [];
displayName = 'Jovo AudioStream';
doNotWaitForTTS = false;
repeatMode?: RepeatMode;
startAudioItemIndex?: number;
Expand Down Expand Up @@ -103,70 +98,55 @@ export class BixbyAudioPlayer {
return this;
}

play(item: Stream) {
this.addAudioStream(item);
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;
}

// -- Helper functions for AudioItem MetaData --
setId(id: string) {
this.audioItem.id = id;
return this;
}
if (!item.id) {
item.id = Date.now().toString();
}

setTitle(title: string) {
this.audioItem.title = title;
return this;
}
if (!item.albumArtUrl) {
item.albumArtUrl = 'https://test.jpg';
}

setSubtitle(subtitle: string) {
this.audioItem.subtitle = subtitle;
return this;
}
if (item.stream && !item.stream.format) {
item.stream.format = 'audio/mp3';
}

setArtist(artist: string) {
this.audioItem.artist = artist;
return this;
}
this.audioItem.push(item);

setAlbumArt(url: string) {
this.audioItem.albumArtUrl = url;
return this;
}

setAlbumName(name: string) {
this.audioItem.albumName = name;
return this;
}
addAudioStreams(items: AudioInfo[]) {
for (const item of items) {
this.addAudioStream(item);
}

setDuration(duration: number) {
this.audioItem.duration = duration;
return this;
}

setMetaData(data: AudioInfo) {
Object.assign(this.audioItem, data);
setAudioStream(item: AudioInfo) {
this.audioItem = [];
this.addAudioStream(item);

return this;
}
}

0 comments on commit eb20952

Please sign in to comment.