AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
ExternalMediaAdapterInterface.h
Go to the documentation of this file.
1 /*
2  * Copyright 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 ALEXA_CLIENT_SDK_ACSDKEXTERNALMEDIAPLAYERINTERFACES_INCLUDE_ACSDKEXTERNALMEDIAPLAYERINTERFACES_EXTERNALMEDIAADAPTERINTERFACE_H_
17 #define ALEXA_CLIENT_SDK_ACSDKEXTERNALMEDIAPLAYERINTERFACES_INCLUDE_ACSDKEXTERNALMEDIAPLAYERINTERFACES_EXTERNALMEDIAADAPTERINTERFACE_H_
18 
19 #include <chrono>
20 #include <set>
21 #include <string>
22 #include <unordered_map>
23 
26 
27 namespace alexaClientSDK {
28 namespace acsdkExternalMediaPlayerInterfaces {
29 
32 enum class RequestType {
34  INIT,
35 
37  DEINIT,
38 
40  LOGIN,
41 
43  LOGOUT,
44 
46  REGISTER,
47 
49  PLAY,
50 
52  RESUME,
53 
55  PAUSE,
56 
58  STOP,
59 
62 
64  NEXT,
65 
67  PREVIOUS,
68 
70  START_OVER,
71 
74 
76  REWIND,
77 
80 
83 
86 
89 
92 
95 
97  FAVORITE,
98 
101 
103  UNFAVORITE,
104 
107 
109  SEEK,
110 
112  ADJUST_SEEK,
113 
115  SET_VOLUME,
116 
119 
121  SET_MUTE,
122 
125 
127  GET_INFO,
128 
130  ADD_USER,
131 
133  RESET_USER,
134 
136  NONE
137 };
138 
141  PLAY,
142 
144  RESUME,
145 
147  PAUSE,
148 
150  STOP,
151 
153  NEXT,
154 
156  PREVIOUS,
157 
159  START_OVER,
160 
162  FAST_FORWARD,
163 
165  REWIND,
166 
169 
172 
175 
178 
181 
184 
186  FAVORITE,
187 
189  UNFAVORITE,
190 
192  SEEK,
193 
195  ADJUST_SEEK,
196 
197 };
198 
202 enum class ChangeCauseType {
205 
208 
211 
213  RULE_TRIGGER,
214 
217 };
218 
222 enum class Favorites {
224  FAVORITED,
225 
227  UNFAVORITED,
228 
230  NOT_RATED
231 };
232 
236 enum class MediaType {
238  TRACK,
239 
241  PODCAST,
242 
244  STATION,
245 
247  AD,
248 
250  SAMPLE,
251 
253  OTHER
254 };
255 
259 enum class Navigation {
263  DEFAULT,
267  NONE,
271  FOREGROUND
272 };
273 
281  switch (navigation) {
282  case Navigation::DEFAULT:
283  return "DEFAULT";
284  case Navigation::NONE:
285  return "NONE";
287  return "FOREGROUND";
288  }
289  return "";
290 }
291 
299 inline std::ostream& operator<<(std::ostream& stream, const Navigation& navigation) {
300  return stream << navigationToString(navigation);
301 }
302 
310  if (str == "DEFAULT") {
311  return Navigation::DEFAULT;
312  } else if (str == "NONE") {
313  return Navigation::NONE;
314  } else if (str == "FOREGROUND") {
315  return Navigation::FOREGROUND;
316  } else {
317  // default to DEFAULT
318  return Navigation::DEFAULT;
319  }
320 }
321 
326  /*
327  * Default Constructor.
328  */
330 
334 
338 
341 
343  bool loggedIn;
344 
348 
350  bool isGuest;
351 
353  bool launched;
354 
359  bool active;
360 
363 
366 
370 
374 
381 
383  std::chrono::milliseconds tokenRefreshInterval;
384 };
385 
392 
396 
399 
401  std::set<SupportedPlaybackOperation> supportedOperations;
402 
404  std::chrono::milliseconds trackOffset;
405 
408 
411 
414 
418 
421 
426 
433 
436 
440 
444 
447 
452 
455 
460 
463 
466 
469 
472 
476 
480 
484 
486  std::chrono::milliseconds duration;
487 
490 };
491 
496 public:
498  AdapterState() = default;
499 
502 
505 };
506 
515 public:
521  explicit ExternalMediaAdapterInterface(const std::string& adapterName);
522 
526  virtual ~ExternalMediaAdapterInterface() = default;
527 
535  int64_t index;
537  std::chrono::milliseconds offset;
545  bool preload;
550 
573  const std::string& playContextToken,
574  int64_t index,
575  std::chrono::milliseconds offset,
576  const std::string& skillToken,
577  const std::string& playbackSessionId,
578  Navigation navigation,
579  bool preload,
580  const avsCommon::avs::PlayRequestor& playRequestor,
581  const std::string& playbackTarget) :
582  playContextToken{playContextToken},
583  index{index},
584  offset{offset},
585  skillToken{skillToken},
586  playbackSessionId{playbackSessionId},
587  navigation{navigation},
588  preload{preload},
589  playRequestor(playRequestor),
590  playbackTarget{playbackTarget} {
591  }
592  };
593 
595  virtual void init() = 0;
596 
598  virtual void deInit() = 0;
599 
610  virtual void handleLogin(
611  const std::string& accessToken,
612  const std::string& userName,
613  bool forceLogin,
614  std::chrono::milliseconds tokenRefreshInterval) = 0;
615 
619  virtual void handleLogout() = 0;
620 
627  virtual void handlePlay(const HandlePlayParams& params) = 0;
628 
638  virtual void handlePlayControl(RequestType requestType, const std::string& playbackTarget) = 0;
639 
645  virtual void handleSeek(std::chrono::milliseconds offset) = 0;
646 
652  virtual void handleAdjustSeek(std::chrono::milliseconds deltaOffset) = 0;
653 
664  virtual void handleAuthorized(
665  bool authorized,
666  const std::string& playerId,
667  const std::string& defaultSkillToken) = 0;
668 
670  virtual AdapterState getState() = 0;
671 
678  virtual std::chrono::milliseconds getOffset() = 0;
679 };
680 
681 inline AdapterSessionState::AdapterSessionState() : loggedIn{false}, isGuest{false}, launched{false}, active{false} {
682 }
683 
685  state{"IDLE"},
686  trackOffset{0},
687  shuffleEnabled{false},
688  repeatEnabled{false},
691  duration{0} {
692 }
693 
695  RequiresShutdown{adapterName} {
696 }
697 
705  switch (requestType) {
706  case RequestType::INIT:
707  return "INIT";
708  case RequestType::DEINIT:
709  return "DEINIT";
710  case RequestType::LOGIN:
711  return "LOGIN";
712  case RequestType::LOGOUT:
713  return "LOGOUT";
715  return "REGISTER";
716  case RequestType::PLAY:
717  return "PLAY";
718  case RequestType::RESUME:
719  return "RESUME";
720  case RequestType::PAUSE:
721  return "PAUSE";
722  case RequestType::STOP:
723  return "STOP";
725  return "PAUSE_RESUME_TOGGLE";
726  case RequestType::NEXT:
727  return "NEXT";
729  return "PREVIOUS";
731  return "START_OVER";
733  return "FAST_FORWARD";
734  case RequestType::REWIND:
735  return "REWIND";
737  return "ENABLE_REPEAT_ONE";
739  return "DISABLE_REPEAT_ONE";
741  return "ENABLE_REPEAT";
743  return "DISABLE_REPEAT";
745  return "ENABLE_SHUFFLE";
747  return "DISABLE_SHUFFLE";
749  return "FAVORITE";
751  return "DESELECT_FAVORITE";
753  return "UNFAVORITE";
755  return "DESELECT_UNFAVORITE";
756  case RequestType::SEEK:
757  return "SEEK";
759  return "ADJUST_SEEK";
761  return "SET_VOLUME";
763  return "ADJUST_VOLUME";
765  return "SET_MUTE";
767  return "SET_DISPLAY_NAME";
769  return "GET_INFO";
771  return "ADD_USER";
773  return "RESET_USER";
774  case RequestType::NONE:
775  return "NONE";
776  }
777 
778  return "unknown request type";
779 }
780 
788  switch (operation) {
790  return "Play";
792  return "Resume";
794  return "Pause";
796  return "Stop";
798  return "Next";
800  return "Previous";
802  return "StartOver";
804  return "FastForward";
806  return "Rewind";
808  return "EnableRepeat";
810  return "EnableRepeatOne";
812  return "DisableRepeat";
814  return "DisableRepeatOne";
816  return "EnableShuffle";
818  return "DisableShuffle";
820  return "Favorite";
822  return "Unfavorite";
824  return "SetSeekPosition";
826  return "AdjustSeekPosition";
827  }
828 
829  return "unknown operation";
830 }
831 
839  switch (changeType) {
841  return "VOICE_INTERACTION";
843  return "PHYSICAL_INTERACTION";
845  return "APP_INTERACTION";
847  return "RULE_TRIGGER";
849  return "PERIODIC_POLL";
850  }
851 
852  return "unknown changeTrigger";
853 }
854 
862  switch (rating) {
864  return "FAVORITED";
866  return "UNFAVORITED";
868  return "NOT_RATED";
869  }
870 
871  return "unknown rating";
872 }
873 
881  switch (mediaType) {
882  case MediaType::TRACK:
883  return "TRACK";
884  case MediaType::PODCAST:
885  return "PODCAST";
886  case MediaType::STATION:
887  return "STATION";
888  case MediaType::AD:
889  return "AD";
890  case MediaType::SAMPLE:
891  return "SAMPLE";
892  case MediaType::OTHER:
893  return "OTHER";
894  }
895 
896  return "unknown mediaType";
897 }
898 
899 inline std::string SHUFFLE_STATUS_STRING(bool shuffleEnabled) {
900  return (shuffleEnabled == true) ? "SHUFFLED" : "NOT_SHUFFLED";
901 }
902 
903 inline std::string REPEAT_STATUS_STRING(bool repeatEnabled) {
904  return (repeatEnabled == true) ? "REPEATED" : "NOT_REPEATED";
905 }
906 
907 } // namespace acsdkExternalMediaPlayerInterfaces
908 } // namespace alexaClientSDK
909 
910 #endif // ALEXA_CLIENT_SDK_ACSDKEXTERNALMEDIAPLAYERINTERFACES_INCLUDE_ACSDKEXTERNALMEDIAPLAYERINTERFACES_EXTERNALMEDIAADAPTERINTERFACE_H_
std::string navigationToString(Navigation navigation)
Definition: ExternalMediaAdapterInterface.h:280
std::string coverId
Definition: ExternalMediaAdapterInterface.h:475
std::string albumName
The display name of the currently playing album.
Definition: ExternalMediaAdapterInterface.h:454
The media type is something other than track/podcast/station/ad/sample.
avsCommon::avs::PlayRequestor playRequestor
PlayRequestor for indicating who requested playback.
Definition: ExternalMediaAdapterInterface.h:547
std::string artistId
Definition: ExternalMediaAdapterInterface.h:451
std::string playerId
Definition: ExternalMediaAdapterInterface.h:333
std::string playbackSessionId
Definition: ExternalMediaAdapterInterface.h:373
std::string artistName
The display name for the currently playing artist.
Definition: ExternalMediaAdapterInterface.h:446
bool repeatEnabled
Bool to identify if looping of songs is enabled or not.
Definition: ExternalMediaAdapterInterface.h:410
std::string largeURL
The URL for large cover art image resource} .
Definition: ExternalMediaAdapterInterface.h:471
AdapterSessionState sessionState
Variable to hold the session state.
Definition: ExternalMediaAdapterInterface.h:501
std::string skillToken
Definition: ExternalMediaAdapterInterface.h:369
std::string playbackSource
The display name for current playback context, e.g. playlist name.
Definition: ExternalMediaAdapterInterface.h:420
Navigation stringToNavigation(const std::string &str)
Definition: ExternalMediaAdapterInterface.h:309
std::string mediumURL
The URL for medium cover art image resource} .
Definition: ExternalMediaAdapterInterface.h:468
std::string trackId
Definition: ExternalMediaAdapterInterface.h:439
Navigation navigation
Navigation for indicating foreground or not.
Definition: ExternalMediaAdapterInterface.h:543
Set the name the external media player will show for this device.
std::string albumId
Definition: ExternalMediaAdapterInterface.h:459
bool loggedIn
Flag that identifies if a user is currently logged in or not.
Definition: ExternalMediaAdapterInterface.h:343
std::string type
Definition: ExternalMediaAdapterInterface.h:417
std::string endpointId
The unique device endpoint.
Definition: ExternalMediaAdapterInterface.h:340
bool shuffleEnabled
Bool to identify if shuffling is enabled or not.
Definition: ExternalMediaAdapterInterface.h:407
RequestType
Definition: ExternalMediaAdapterInterface.h:32
::std::string string
Definition: gtest-port.h:1097
Navigation
Definition: ExternalMediaAdapterInterface.h:259
std::string playbackSourceId
Definition: ExternalMediaAdapterInterface.h:425
std::string tinyURL
The URL for tiny cover art image resource} .
Definition: ExternalMediaAdapterInterface.h:462
std::string ChangeTriggerToString(ChangeCauseType changeType)
Definition: ExternalMediaAdapterInterface.h:838
Favorites favorites
The favorite status {"FAVORITED"/"UNFAVORITED"/"NOT_RATED"}.
Definition: ExternalMediaAdapterInterface.h:413
Definition: ExternalMediaAdapterInterface.h:495
bool active
Definition: ExternalMediaAdapterInterface.h:359
std::string trackName
The display name for the currently playing trackname of the track.
Definition: ExternalMediaAdapterInterface.h:435
ChangeCauseType
Definition: ExternalMediaAdapterInterface.h:202
bool isGuest
Flag that identifies if the user currently logged in is a guest or not.
Definition: ExternalMediaAdapterInterface.h:350
std::string userName
Definition: ExternalMediaAdapterInterface.h:347
std::string RequestTypeToString(RequestType requestType)
Definition: ExternalMediaAdapterInterface.h:704
std::string spiVersion
The service provider interface (SPI) version.
Definition: ExternalMediaAdapterInterface.h:362
std::string trackNumber
Definition: ExternalMediaAdapterInterface.h:443
std::set< SupportedPlaybackOperation > supportedOperations
The set of states the default player can move into from its current state.
Definition: ExternalMediaAdapterInterface.h:401
MediaType
Definition: ExternalMediaAdapterInterface.h:236
std::string playbackSessionId
Playback session id for identifying the session.
Definition: ExternalMediaAdapterInterface.h:541
MediaType mediaType
Definition: ExternalMediaAdapterInterface.h:483
AdapterPlaybackState playbackState
Variable to hold the playback state.
Definition: ExternalMediaAdapterInterface.h:504
std::string playbackTarget
Playback target to play on.
Definition: ExternalMediaAdapterInterface.h:549
std::string playbackId
Definition: ExternalMediaAdapterInterface.h:432
std::string smallURL
The URL for small cover art image resource} .
Definition: ExternalMediaAdapterInterface.h:465
std::string SHUFFLE_STATUS_STRING(bool shuffleEnabled)
Definition: ExternalMediaAdapterInterface.h:899
std::string localPlayerId
Definition: ExternalMediaAdapterInterface.h:337
std::string mediaProvider
Definition: ExternalMediaAdapterInterface.h:479
bool preload
Whether or not to preload first.
Definition: ExternalMediaAdapterInterface.h:545
std::string playContextToken
Play context token for specifying what to play.
Definition: ExternalMediaAdapterInterface.h:533
The state change was triggered as result of voice interaction.
std::string accessToken
Definition: ExternalMediaAdapterInterface.h:380
std::string skillToken
Associated skillToken.
Definition: ExternalMediaAdapterInterface.h:539
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
AdapterSessionState()
Definition: ExternalMediaAdapterInterface.h:681
HandlePlayParams(const std::string &playContextToken, int64_t index, std::chrono::milliseconds offset, const std::string &skillToken, const std::string &playbackSessionId, Navigation navigation, bool preload, const avsCommon::avs::PlayRequestor &playRequestor, const std::string &playbackTarget)
Definition: ExternalMediaAdapterInterface.h:572
std::chrono::milliseconds offset
Offset to play from.
Definition: ExternalMediaAdapterInterface.h:537
std::chrono::milliseconds duration
Media item duration in milliseconds.
Definition: ExternalMediaAdapterInterface.h:486
bool launched
Flag that identifies if an application has been launched or not.
Definition: ExternalMediaAdapterInterface.h:353
std::string playerCookie
The playerCookie to select version-specific content or actions.
Definition: ExternalMediaAdapterInterface.h:365
ExternalMediaAdapterInterface(const std::string &adapterName)
Definition: ExternalMediaAdapterInterface.h:694
std::chrono::milliseconds trackOffset
The offset of the track in milliseconds.
Definition: ExternalMediaAdapterInterface.h:404
Mark a track as not a favorite.(thumbs down true)
std::string RatingToString(Favorites rating)
Definition: ExternalMediaAdapterInterface.h:861
Adjust volume level relative to the existing volume.
std::chrono::milliseconds tokenRefreshInterval
The validity period of the token in milliseconds.
Definition: ExternalMediaAdapterInterface.h:383
std::string MediaTypeToString(MediaType mediaType)
Definition: ExternalMediaAdapterInterface.h:880
Definition: PlayRequestor.h:29
AdapterPlaybackState()
Default constructor.
Definition: ExternalMediaAdapterInterface.h:684
int64_t index
Index for track.
Definition: ExternalMediaAdapterInterface.h:535
avsCommon::avs::PlayRequestor playRequestor
The PlayRequestor object from the PLAY directive.
Definition: ExternalMediaAdapterInterface.h:489
std::ostream & operator<<(std::ostream &stream, const AdapterEvent &event)
Definition: AdapterUtils.h:85
std::string playerId
Definition: ExternalMediaAdapterInterface.h:395
std::string state
The players current state.
Definition: ExternalMediaAdapterInterface.h:398
std::string SupportedPlaybackOperationToString(SupportedPlaybackOperation operation)
Definition: ExternalMediaAdapterInterface.h:787
Favorites
Definition: ExternalMediaAdapterInterface.h:222
SupportedPlaybackOperation
Definition: ExternalMediaAdapterInterface.h:139
std::string REPEAT_STATUS_STRING(bool repeatEnabled)
Definition: ExternalMediaAdapterInterface.h:903

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0