@@ -11,12 +11,31 @@ const helpers = require('./_helpers');
1111 *
1212 * @param app
1313 */
14- function handler ( app ) {
15- return helpers . playSong ( { app, skip : 'forward' } )
16- . then ( ( { currentSongData } ) => {
17- if ( ! currentSongData ) {
14+ function handler ( app ) {
15+ const requestType = app . params . getByName ( 'type' ) ;
16+ const playerActivity = app . handlerInput &&
17+ app . handlerInput . requestEnvelope &&
18+ app . handlerInput . requestEnvelope . context &&
19+ app . handlerInput . requestEnvelope . context . AudioPlayer &&
20+ app . handlerInput . requestEnvelope . context . AudioPlayer . playerActivity ;
21+ const isPlaybackController = typeof requestType === 'string' &&
22+ requestType . startsWith ( 'PlaybackController.' ) ;
23+ // Only suppress speech for PlaybackController events (where speech is forbidden).
24+ // For voice intents (AMAZON.NextIntent), include speech to keep the session alive
25+ // so subsequent "Alexa next/skip" commands continue routing to the skill.
26+ const mediaResponseOnly = isPlaybackController ;
27+
28+ debug ( 'Request type:' , requestType ) ;
29+ debug ( 'Is PlaybackController:' , isPlaybackController ) ;
30+ debug ( 'mediaResponseOnly:' , mediaResponseOnly ) ;
31+ debug ( 'Player activity:' , playerActivity ) ;
32+
33+ return helpers . playSong ( { app, skip : 'forward' , mediaResponseOnly } )
34+ . then ( ( res ) => {
35+ const { currentSongData } = res || { } ;
36+ if ( res && ! currentSongData ) {
1837 error ( 'We do not have any data for previous song' ) ;
19- } else {
38+ } else if ( res ) {
2039 return skippedSong ( app , {
2140 albumId : currentSongData . album . id ,
2241 filename : currentSongData . filename
@@ -25,6 +44,10 @@ function handler (app) {
2544 } )
2645 . catch ( e => {
2746 debug ( 'It could be an error:' , e ) ;
47+ if ( mediaResponseOnly ) {
48+ app . stopPlayback ( ) ;
49+ return null ;
50+ }
2851 return dialog . ask ( app , strings . events . playlistIsEnded ) ;
2952 } ) ;
3053}
0 commit comments