Alexa Skills:AudioPlayer HLS流URL无法正常工作

时间:2017-06-26 18:34:33

标签: javascript aws-lambda alexa alexa-skills-kit

我正在使用" AudioPlayer" " Alexa Skill Kit"流式传输HLS音频格式URL。我没有从AWS Lambda和Developer Portal收到任何错误。我正在使用Silent Echo(https://silentecho.bespoken.io/)进行测试。 Alexa能够播放MP3格式的URL,以及我通过论坛找到的一些HLS。但是,我的HLS URL无效。

我的HLS网址:http://cpdc101-lh.akamaihd.net/i/ISNCPDCMB1_1@314337/master.m3u8

其他HLS网址:https://as-hls-ww-live.bbcfmt.hs.llnwd.net/pool_6/live/bbc_radio_fourfm/bbc_radio_fourfm.isml/bbc_radio_fourfm-audio%3d96000.norewind.m3u8

其他HLS网址正在播放,但我什么也听不到。尽管如此,当我的HLS with Silent Echo出现这个错误时,他们的工作仍然存在。#34;请求的技能响应存在问题。"有没有人看到我的HLS链接和他们的链接之间的区别?

任何人都可以帮我弄清楚如何让这个HLS网址生效吗?

代码:



var lastPlayedByUser = {};
var streamURL = "http://cpdc101-lh.akamaihd.net/i/ISNCPDCMB1_1@314337/master.m3u8";


exports.handler = function(event, context) {
    var player = new SidRothPlayer(event, context);
    player.handle();
};

var SidRothPlayer = function (event, context) {
    this.event = event;
    this.context = context;
};

SidRothPlayer.prototype.handle = function () {
    var requestType = this.event.request.type;
    var userId = this.event.context ? this.event.context.System.user.userId : this.event.session.user.userId;

   if (requestType === "LaunchRequest") {
        this.play(streamURL, 0);

    } else  if (requestType === "IntentRequest") {
        var intent = this.event.request.intent;
        if (intent.name === "Play") {
            this.play(streamURL, 0);

        } else if (intent.name === "AMAZON.PauseIntent") {
            this.stop();

        } else if (intent.name === "AMAZON.ResumeIntent") {
            var lastPlayed = this.loadLastPlayed(userId);
            var offsetInMilliseconds = 0;
            if (lastPlayed !== null) {
                offsetInMilliseconds = lastPlayed.request.offsetInMilliseconds;
            }

            this.play(streamURL, offsetInMilliseconds);
        }
    } else if (requestType === "AudioPlayer.PlaybackStopped") {
        this.saveLastPlayed(userId, this.event);
        this.context.succeed(true);
    }
};


 SidRothPlayer.prototype.play = function (audioURL, offsetInMilliseconds) {
    var response = {
        version: "1.0",
        response: {
            shouldEndSession: true,
            directives: [
                {
                    type: "AudioPlayer.Play",
                    playBehavior: "REPLACE_ALL", 
                    audioItem: {
                        stream: {
                            url: audioURL,
                            token: "0", 
                            expectedPreviousToken: null, 
                            offsetInMilliseconds: offsetInMilliseconds
                        }
                    }
                }
            ]
        }
    };

    this.context.succeed(response);
};


SidRothPlayer.prototype.stop = function () {
    var response = {
        version: "1.0",
        response: {
            shouldEndSession: true,
            directives: [
                {
                    type: "AudioPlayer.Stop"
                }
            ]
        }
    };

    this.context.succeed(response);
};

SidRothPlayer.prototype.saveLastPlayed = function (userId, lastPlayed) {
    lastPlayedByUser[userId] = lastPlayed;
};

SidRothPlayer.prototype.loadLastPlayed = function (userId) {
    var lastPlayed = null;
    if (userId in lastPlayedByUser) {
        lastPlayed = lastPlayedByUser[userId];
    }
    return lastPlayed;
};




2 个答案:

答案 0 :(得分:1)

您的流网址应为https。

答案 1 :(得分:0)

谢谢Wejd DAGHFOUS。我将URL更改为HTTPS,错误消失了!我现在可以玩了,但是和其他HLS链接一样,我听不到任何声音。

谢谢joseluismg。你知道HLS是否只能播放音频吗?