diff --git a/tests/www/js/tests_auto.js b/tests/www/js/tests_auto.js index 5e521b5..2ade66e 100644 --- a/tests/www/js/tests_auto.js +++ b/tests/www/js/tests_auto.js @@ -964,6 +964,30 @@ assert.fail('Unexpected Error: ' + err.code + ': ' + err.description); }); }); + it('session.loadMedia should be able to load live stream audio media', function (done) { + this.timeout(90000); + var mediaInfo = mediaUtils.getMediaInfoItem('LIVE_AUDIO'); + session.loadMedia(new chrome.cast.media.LoadRequest(mediaInfo), function (m) { + media = m; + utils.testMediaProperties(media, true); + mediaUtils.assertMediaInfoItemEquals(media.media, mediaInfo); + media.addUpdateListener(function listener (isAlive) { + assert.isTrue(isAlive); + utils.testMediaProperties(media, true); + mediaUtils.assertMediaInfoItemEquals(media.media, mediaInfo); + assert.oneOf(media.playerState, [ + chrome.cast.media.PlayerState.PLAYING, + chrome.cast.media.PlayerState.BUFFERING]); + if (media.playerState === chrome.cast.media.PlayerState.PLAYING) { + console.log(media); + media.removeUpdateListener(listener); + done(); + } + }); + }, function (err) { + assert.fail('Unexpected Error: ' + err.code + ': ' + err.description); + }); + }); it('session.loadMedia should be able to load remote image and return the PhotoMediaMetadata', function (done) { var mediaInfo = mediaUtils.getMediaInfoItem('IMAGE', chrome.cast.media.MetadataType.PHOTO); session.loadMedia(new chrome.cast.media.LoadRequest(mediaInfo), function (m) { diff --git a/tests/www/lib/mediaGenerateAndAssert.js b/tests/www/lib/mediaGenerateAndAssert.js index 25dd1c6..77f40ac 100644 --- a/tests/www/lib/mediaGenerateAndAssert.js +++ b/tests/www/lib/mediaGenerateAndAssert.js @@ -11,6 +11,7 @@ var audioUrl = 'https://ia800306.us.archive.org/26/items/1939RadioNews/1939-10-24-CBS-Elmer-Davis-Reports-City-Of-Flint-Still-Missing.mp3'; var imageUrl = 'https://ia800705.us.archive.org/1/items/GoodHousekeeping193810/Good%20Housekeeping%201938-10.jpg'; + var liveAudioUrl = 'http://relay.publicdomainproject.org/classical.mp3'; var videoUrl = 'https://ia801302.us.archive.org/1/items/TheWater_201510/TheWater.mp4'; var mediaUtils = { @@ -23,6 +24,9 @@ }, 'IMAGE': function () { return new chrome.cast.media.MediaInfo(imageUrl, 'image/jpeg'); + }, + 'LIVE_AUDIO': function () { + return new chrome.cast.media.MediaInfo(liveAudioUrl, 'audio/mpeg'); } } }; diff --git a/tests/www/lib/utils.js b/tests/www/lib/utils.js index d8bb53e..5ed8cd2 100644 --- a/tests/www/lib/utils.js +++ b/tests/www/lib/utils.js @@ -279,14 +279,14 @@ assert.isFunction(session.loadMedia); }; - utils.testMediaProperties = function (media) { + utils.testMediaProperties = function (media, isLiveStream) { assert.instanceOf(media, chrome.cast.media.Media); assert.isNumber(media.currentItemId); assert.isNumber(media.currentTime); if (media.idleReason) { assert.oneOf(media.idleReason, utils.getObjectValues(chrome.cast.media.IdleReason)); } - utils.testMediaInfoProperties(media.media); + utils.testMediaInfoProperties(media.media, isLiveStream); assert.isNumber(media.mediaSessionId); assert.isNumber(media.playbackRate); assert.oneOf(media.playerState, utils.getObjectValues(chrome.cast.media.PlayerState)); @@ -298,14 +298,19 @@ assert.isFunction(media.removeUpdateListener); }; - utils.testMediaInfoProperties = function (mediaInfo) { + utils.testMediaInfoProperties = function (mediaInfo, isLiveStream) { // queue items contain a subset of identical properties utils.testQueueItemMediaInfoProperties(mediaInfo); // properties that are exclusive (or mandatory) to media.media - assert.isNumber(mediaInfo.duration); - if (mediaInfo.contentType.toLowerCase().indexOf('video') > -1 - || mediaInfo.contentType.toLowerCase().indexOf('audio') > -1) { - assert.isAbove(mediaInfo.duration, 0); + if (isLiveStream) { + // Live stream has null duration + assert.isNull(mediaInfo.duration); + } else { + assert.isNumber(mediaInfo.duration); + if (mediaInfo.contentType.toLowerCase().indexOf('video') > -1 + || mediaInfo.contentType.toLowerCase().indexOf('audio') > -1) { + assert.isAbove(mediaInfo.duration, 0); + } } assert.isArray(mediaInfo.tracks); };