CB-8428 Fix tests on Windows if no audio playback hardware is available
diff --git a/src/windows/MediaProxy.js b/src/windows/MediaProxy.js
index a76c800..cb1457b 100644
--- a/src/windows/MediaProxy.js
+++ b/src/windows/MediaProxy.js
@@ -96,8 +96,12 @@
stopPlayingAudio:function(win, lose, args) {
var id = args[0];
try {
- (Media.get(id)).node.pause();
- (Media.get(id)).node.currentTime = 0;
+ var thisM = Media.get(id);
+ thisM.node.pause();
+ if (thisM.node.currentTime != 0) {
+ // prevents failing w/ InvalidStateError if playback has not started
+ thisM.node.currentTime = 0;
+ }
Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED);
win();
} catch (err) {
diff --git a/tests/tests.js b/tests/tests.js
index ea8826d..b18535d 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -18,6 +18,10 @@
* under the License.
*
*/
+
+var isWindows = cordova.platformId == 'windows8' || cordova.platformId == 'windows';
+// detect whether audio hardware is available and enabled
+var isAudioSupported = isWindows ? Windows.Media.Devices.MediaDevice.getDefaultAudioRenderId(Windows.Media.Devices.AudioDeviceRole.default) : true;
exports.defineAutoTests = function () {
var failed = function (done, msg, error) {
@@ -180,6 +184,11 @@
});
it("media.spec.16 position should be set properly", function (done) {
+ // no audio hardware available
+ if (!isAudioSupported) {
+ pending();
+ return;
+ }
var self = this;
var mediaFile = 'http://cordova.apache.org/downloads/BlueZedEx.mp3',
mediaState = Media.MEDIA_STOPPED,
@@ -208,6 +217,11 @@
});
it("media.spec.17 duration should be set properly", function (done) {
+ // no audio hardware available
+ if (!isAudioSupported) {
+ pending();
+ return;
+ }
var self = this;
if (cordova.platformId === 'blackberry10') {
expect(true).toFailWithMessage('Platform does not supported this feature');