Alexa Auto SDK  2.3.0
ExternalMediaAdapter.h
1 /*
2  * Copyright 2017-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef AACE_ALEXA_EXTERNAL_MEDIA_ADAPTER_H
17 #define AACE_ALEXA_EXTERNAL_MEDIA_ADAPTER_H
18 
19 #include <chrono>
20 #include <string>
21 
22 #include "AACE/Core/PlatformInterface.h"
23 #include "AACE/Audio/AudioOutput.h"
24 
25 #include "AlexaEngineInterfaces.h"
26 
29 namespace aace {
30 namespace alexa {
31 
32 class ExternalMediaAdapter : public aace::core::PlatformInterface {
33 public:
34  using DiscoveredPlayerInfo = ExternalMediaAdapterEngineInterface::DiscoveredPlayerInfo;
35  using MutedState = aace::audio::AudioOutput::MutedState;
36 
40  enum class PlayControlType {
44  PAUSE,
48  RESUME,
52  STOP,
56  NEXT,
60  PREVIOUS,
64  START_OVER,
68  FAST_FORWARD,
72  REWIND,
76  ENABLE_REPEAT_ONE,
80  ENABLE_REPEAT,
84  DISABLE_REPEAT,
88  ENABLE_SHUFFLE,
92  DISABLE_SHUFFLE,
96  FAVORITE,
100  UNFAVORITE,
105  PAUSE_RESUME_TOGGLE
106  };
107 
111  enum class SupportedPlaybackOperation {
115  PLAY,
119  PAUSE,
123  STOP,
127  NEXT,
131  PREVIOUS,
135  START_OVER,
139  FAST_FORWARD,
143  REWIND,
147  ENABLE_REPEAT,
151  ENABLE_REPEAT_ONE,
155  DISABLE_REPEAT,
159  ENABLE_SHUFFLE,
163  DISABLE_SHUFFLE,
167  FAVORITE,
171  UNFAVORITE,
175  SEEK,
179  ADJUST_SEEK
180  };
181 
185  enum class Favorites {
189  FAVORITED,
193  UNFAVORITED,
197  NOT_RATED
198  };
199 
203  enum class MediaType {
207  TRACK,
211  PODCAST,
215  STATION,
219  AD,
223  SAMPLE,
227  OTHER
228  };
229 
233  enum class Navigation {
237  DEFAULT,
241  NONE,
245  FOREGROUND
246  };
247 
251  class SessionState {
252  public:
256  SessionState() = default;
257 
259  std::string endpointId;
260 
262  bool loggedIn;
263 
265  std::string userName;
266 
268  bool isGuest;
269 
271  bool launched;
272 
277  bool active;
278 
283  std::string accessToken;
284 
286  std::chrono::milliseconds tokenRefreshInterval;
287 
289  std::string playerCookie;
290 
292  std::string spiVersion;
293  };
294 
299  public:
301  PlaybackState() = default;
302 
304  std::string state;
305 
307  std::vector<SupportedPlaybackOperation> supportedOperations;
308 
310  std::chrono::milliseconds trackOffset;
311 
314 
317 
319  Favorites favorites;
320 
322  std::string type;
323 
325  std::string playbackSource;
326 
329  std::string playbackSourceId;
330 
332  std::string trackName;
333 
335  std::string trackId;
336 
339  std::string trackNumber;
340 
342  std::string artistName;
343 
346  std::string artistId;
347 
349  std::string albumName;
350 
353  std::string albumId;
354 
356  std::string tinyURL;
357 
359  std::string smallURL;
360 
362  std::string mediumURL;
363 
365  std::string largeURL;
366 
369  std::string coverId;
370 
373  std::string mediaProvider;
374 
376  MediaType mediaType;
377 
379  std::chrono::milliseconds duration;
380  };
381 
386  public:
388  ExternalMediaAdapterState() = default;
389 
392 
395  };
396 
401  public:
403  std::string localPlayerId;
407  std::string defaultSkillToken;
408  // The playerId that identifies this player
409  std::string playerId;
410  };
411 
412 protected:
413  ExternalMediaAdapter() = default;
414 
415 public:
416  virtual ~ExternalMediaAdapter();
417 
434  virtual bool login(
435  const std::string& localPlayerId,
436  const std::string& accessToken,
437  const std::string& userName,
438  bool forceLogin,
439  std::chrono::milliseconds tokenRefreshInterval) = 0;
440 
449  virtual bool logout(const std::string& localPlayerId) = 0;
450 
469  virtual bool play(
470  const std::string& localPlayerId,
471  const std::string& playContextToken,
472  int64_t index,
473  std::chrono::milliseconds offset,
474  bool preload,
475  Navigation navigation) = 0;
476 
480  virtual bool play(
481  const std::string& localPlayerId,
482  const std::string& playContextToken,
483  int64_t index,
484  std::chrono::milliseconds offset,
485  bool preload,
486  Navigation navigation,
487  const std::string& playbackSessionId,
488  const std::string& skillToken);
489 
502  virtual bool playControl(const std::string& localPlayerId, PlayControlType controlType) = 0;
503 
514  virtual bool seek(const std::string& localPlayerId, std::chrono::milliseconds offset) = 0;
515 
526  virtual bool adjustSeek(const std::string& localPlayerId, std::chrono::milliseconds deltaOffset) = 0;
527 
542  virtual bool authorize(const std::vector<AuthorizedPlayerInfo>& authorizedPlayers) = 0;
543 
549  virtual std::chrono::milliseconds getOffset(const std::string& localPlayerId);
550 
560  virtual bool getState(const std::string& localPlayerId, ExternalMediaAdapterState& state) = 0;
561 
571  virtual bool volumeChanged(float volume) = 0;
572 
582  virtual bool mutedStateChanged(MutedState state) = 0;
583 
584  // ExternalMediaAdapterEngineInterface
585 
591  void reportDiscoveredPlayers(const std::vector<DiscoveredPlayerInfo>& discoveredPlayers);
592 
598  void requestToken(const std::string& localPlayerId);
599 
605  void loginComplete(const std::string& localPlayerId);
606 
612  void logoutComplete(const std::string& localPlayerId);
613 
621  void playerEvent(const std::string& localPlayerId, const std::string& eventName);
622 
636  void playerError(
637  const std::string& localPlayerId,
638  const std::string& errorName,
639  long code,
640  const std::string& description,
641  bool fatal);
642 
648  void setFocus(const std::string& localPlayerId);
649 
650  void removeDiscoveredPlayer(const std::string& localPlayerId);
651 
658  void setEngineInterface(
659  std::shared_ptr<aace::alexa::ExternalMediaAdapterEngineInterface> externalMediaAdapterEngineInterface);
660 
661 private:
662  std::weak_ptr<aace::alexa::ExternalMediaAdapterEngineInterface> m_externalMediaAdapterEngineInterface;
663 };
664 
665 inline std::ostream& operator<<(std::ostream& stream, const ExternalMediaAdapter::PlayControlType& requestType) {
666  switch (requestType) {
667  case ExternalMediaAdapter::PlayControlType::RESUME:
668  stream << "RESUME";
669  break;
670  case ExternalMediaAdapter::PlayControlType::PAUSE:
671  stream << "PAUSE";
672  break;
673  case ExternalMediaAdapter::PlayControlType::STOP:
674  stream << "STOP";
675  break;
676  case ExternalMediaAdapter::PlayControlType::NEXT:
677  stream << "NEXT";
678  break;
679  case ExternalMediaAdapter::PlayControlType::PREVIOUS:
680  stream << "PREVIOUS";
681  break;
682  case ExternalMediaAdapter::PlayControlType::START_OVER:
683  stream << "START_OVER";
684  break;
685  case ExternalMediaAdapter::PlayControlType::FAST_FORWARD:
686  stream << "FAST_FORWARD";
687  break;
688  case ExternalMediaAdapter::PlayControlType::REWIND:
689  stream << "REWIND";
690  break;
691  case ExternalMediaAdapter::PlayControlType::ENABLE_REPEAT_ONE:
692  stream << "ENABLE_REPEAT_ONE";
693  break;
694  case ExternalMediaAdapter::PlayControlType::ENABLE_REPEAT:
695  stream << "ENABLE_REPEAT";
696  break;
697  case ExternalMediaAdapter::PlayControlType::DISABLE_REPEAT:
698  stream << "DISABLE_REPEAT";
699  break;
700  case ExternalMediaAdapter::PlayControlType::ENABLE_SHUFFLE:
701  stream << "ENABLE_SHUFFLE";
702  break;
703  case ExternalMediaAdapter::PlayControlType::DISABLE_SHUFFLE:
704  stream << "DISABLE_SHUFFLE";
705  break;
706  case ExternalMediaAdapter::PlayControlType::FAVORITE:
707  stream << "FAVORITE";
708  break;
709  case ExternalMediaAdapter::PlayControlType::UNFAVORITE:
710  stream << "UNFAVORITE";
711  break;
712  // internal
713  case ExternalMediaAdapter::PlayControlType::PAUSE_RESUME_TOGGLE:
714  stream << "PAUSE_RESUME_TOGGLE";
715  break;
716  }
717  return stream;
718 }
719 
720 inline std::ostream& operator<<(
721  std::ostream& stream,
722  const ExternalMediaAdapter::SupportedPlaybackOperation& supportedPlaybackOperation) {
723  switch (supportedPlaybackOperation) {
724  case ExternalMediaAdapter::SupportedPlaybackOperation::PLAY:
725  stream << "PLAY";
726  break;
727  case ExternalMediaAdapter::SupportedPlaybackOperation::PAUSE:
728  stream << "PAUSE";
729  break;
730  case ExternalMediaAdapter::SupportedPlaybackOperation::STOP:
731  stream << "STOP";
732  break;
733  case ExternalMediaAdapter::SupportedPlaybackOperation::NEXT:
734  stream << "NEXT";
735  break;
736  case ExternalMediaAdapter::SupportedPlaybackOperation::PREVIOUS:
737  stream << "PREVIOUS";
738  break;
739  case ExternalMediaAdapter::SupportedPlaybackOperation::START_OVER:
740  stream << "START_OVER";
741  break;
742  case ExternalMediaAdapter::SupportedPlaybackOperation::FAST_FORWARD:
743  stream << "FAST_FORWARD";
744  break;
745  case ExternalMediaAdapter::SupportedPlaybackOperation::REWIND:
746  stream << "REWIND";
747  break;
748  case ExternalMediaAdapter::SupportedPlaybackOperation::ENABLE_REPEAT:
749  stream << "ENABLE_REPEAT";
750  break;
751  case ExternalMediaAdapter::SupportedPlaybackOperation::ENABLE_REPEAT_ONE:
752  stream << "ENABLE_REPEAT_ONE";
753  break;
754  case ExternalMediaAdapter::SupportedPlaybackOperation::DISABLE_REPEAT:
755  stream << "DISABLE_REPEAT";
756  break;
757  case ExternalMediaAdapter::SupportedPlaybackOperation::ENABLE_SHUFFLE:
758  stream << "ENABLE_SHUFFLE";
759  break;
760  case ExternalMediaAdapter::SupportedPlaybackOperation::DISABLE_SHUFFLE:
761  stream << "DISABLE_SHUFFLE";
762  break;
763  case ExternalMediaAdapter::SupportedPlaybackOperation::FAVORITE:
764  stream << "FAVORITE";
765  break;
766  case ExternalMediaAdapter::SupportedPlaybackOperation::UNFAVORITE:
767  stream << "UNFAVORITE";
768  break;
769  case ExternalMediaAdapter::SupportedPlaybackOperation::SEEK:
770  stream << "SEEK";
771  break;
772  case ExternalMediaAdapter::SupportedPlaybackOperation::ADJUST_SEEK:
773  stream << "ADJUST_SEEK";
774  break;
775  }
776  return stream;
777 }
778 
779 inline std::ostream& operator<<(std::ostream& stream, const ExternalMediaAdapter::Favorites& favorites) {
780  switch (favorites) {
781  case ExternalMediaAdapter::Favorites::FAVORITED:
782  stream << "FAVORITED";
783  break;
784  case ExternalMediaAdapter::Favorites::UNFAVORITED:
785  stream << "UNFAVORITED";
786  break;
787  case ExternalMediaAdapter::Favorites::NOT_RATED:
788  stream << "NOT_RATED";
789  break;
790  }
791  return stream;
792 }
793 
794 inline std::ostream& operator<<(std::ostream& stream, const ExternalMediaAdapter::MediaType& mediaType) {
795  switch (mediaType) {
796  case ExternalMediaAdapter::MediaType::TRACK:
797  stream << "TRACK";
798  break;
799  case ExternalMediaAdapter::MediaType::PODCAST:
800  stream << "PODCAST";
801  break;
802  case ExternalMediaAdapter::MediaType::STATION:
803  stream << "STATION";
804  break;
805  case ExternalMediaAdapter::MediaType::AD:
806  stream << "AD";
807  break;
808  case ExternalMediaAdapter::MediaType::SAMPLE:
809  stream << "SAMPLE";
810  break;
811  case ExternalMediaAdapter::MediaType::OTHER:
812  stream << "OTHER";
813  break;
814  }
815  return stream;
816 }
817 
818 inline std::ostream& operator<<(std::ostream& stream, const ExternalMediaAdapter::Navigation& navigation) {
819  switch (navigation) {
820  case ExternalMediaAdapter::Navigation::DEFAULT:
821  stream << "DEFAULT";
822  break;
823  case ExternalMediaAdapter::Navigation::NONE:
824  stream << "NONE";
825  break;
826  case ExternalMediaAdapter::Navigation::FOREGROUND:
827  stream << "FOREGROUND";
828  break;
829  }
830  return stream;
831 }
832 
833 } // namespace alexa
834 } // namespace aace
835 
836 #endif // AACE_ALEXA_EXTERNAL_MEDIA_ADAPTER_H
MutedState
Definition: AudioOutput.h:69
std::string artistId
Definition: ExternalMediaAdapter.h:346
std::string albumName
The display name of the currently playing album.
Definition: ExternalMediaAdapter.h:349
bool active
Definition: ExternalMediaAdapter.h:277
std::string defaultSkillToken
An opaque token for the domain or skill that is associated with this player.
Definition: ExternalMediaAdapter.h:407
std::string trackId
The arbitrary identifier for currently playing trackid of the track as per the music provider...
Definition: ExternalMediaAdapter.h:335
std::chrono::milliseconds trackOffset
The offset of the track in milliseconds.
Definition: ExternalMediaAdapter.h:310
MediaType mediaType
The Media type enum value from {TRACK, PODCAST, STATION, AD, SAMPLE, OTHER} type of the media...
Definition: ExternalMediaAdapter.h:376
std::string playbackSourceId
Definition: ExternalMediaAdapter.h:329
std::string userName
The userName of the user currently logged in via a Login directive from the AVS.
Definition: ExternalMediaAdapter.h:265
Definition: PlatformInterface.h:29
Definition: ExternalMediaAdapter.h:400
Definition: ExternalMediaAdapter.h:251
std::string mediaProvider
Definition: ExternalMediaAdapter.h:373
std::vector< SupportedPlaybackOperation > supportedOperations
The set of states the default player can move into from its current state.
Definition: ExternalMediaAdapter.h:307
std::string type
The type of the media item. For now hard-coded to ExternalMediaAdapterMusicItem.
Definition: ExternalMediaAdapter.h:322
bool launched
Flag that identifies if an application has been launched or not.
Definition: ExternalMediaAdapter.h:271
std::string accessToken
Definition: ExternalMediaAdapter.h:283
Favorites favorites
The favorite status {"FAVORITED"/"UNFAVORITED"/"NOT_RATED"}.
Definition: ExternalMediaAdapter.h:319
Definition: AddressBook.h:26
std::string artistName
The display name for the currently playing artist.
Definition: ExternalMediaAdapter.h:342
std::string state
The state of the default player - IDLE/STOPPED/PLAYING...
Definition: ExternalMediaAdapter.h:304
std::string tinyURL
The URL for tiny cover art image resource} .
Definition: ExternalMediaAdapter.h:356
bool loggedIn
Flag that identifies if a user is currently logged in or not.
Definition: ExternalMediaAdapter.h:262
std::string trackNumber
Definition: ExternalMediaAdapter.h:339
std::string playbackSource
The display name for current playback context, e.g. playlist name.
Definition: ExternalMediaAdapter.h:325
std::string endpointId
The unique device endpoint.
Definition: ExternalMediaAdapter.h:259
std::chrono::milliseconds tokenRefreshInterval
The validity period of the token in milliseconds.
Definition: ExternalMediaAdapter.h:286
bool isGuest
Flag that identifies if the user currently logged in is a guest or not.
Definition: ExternalMediaAdapter.h:268
std::string coverId
Definition: ExternalMediaAdapter.h:369
SessionState sessionState
Variable to hold the session state.
Definition: ExternalMediaAdapter.h:391
std::string spiVersion
The only spiVersion that currently exists is "1.0".
Definition: ExternalMediaAdapter.h:292
PlaybackState playbackState
Variable to hold the playback state.
Definition: ExternalMediaAdapter.h:394
Definition: ExternalMediaAdapter.h:298
std::string largeURL
The URL for large cover art image resource} .
Definition: ExternalMediaAdapter.h:365
std::string localPlayerId
The opaque token that uniquely identifies the local external player app.
Definition: ExternalMediaAdapter.h:403
std::string playerCookie
A player may declare arbitrary information for itself.
Definition: ExternalMediaAdapter.h:289
bool shuffleEnabled
Bool to identify if shuffling is enabled or not.
Definition: ExternalMediaAdapter.h:313
std::chrono::milliseconds duration
Media item duration in milliseconds.
Definition: ExternalMediaAdapter.h:379
std::string trackName
The display name for the currently playing trackname of the track.
Definition: ExternalMediaAdapter.h:332
std::string smallURL
The URL for small cover art image resource} .
Definition: ExternalMediaAdapter.h:359
std::string mediumURL
The URL for medium cover art image resource} .
Definition: ExternalMediaAdapter.h:362
bool repeatEnabled
Bool to identify if looping of songs is enabled or not.
Definition: ExternalMediaAdapter.h:316
std::string albumId
Definition: ExternalMediaAdapter.h:353
bool authorized
Authorization status.
Definition: ExternalMediaAdapter.h:405

Alexa Auto SDK 2.3.0 - Copyright 2017-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0