}];
jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%d);", @"cordova.require('cordova-plugin-media.Media').onStatus", mediaId, MEDIA_STATE, MEDIA_STOPPED];
} else {
- // cannot seek, do nothing
+ // cannot seek, wrong state
+ CDVMediaError errcode = MEDIA_ERR_NONE_ACTIVE;
+ NSString* errMsg = @"Cannot service stop request until the avPlayer is in 'AVPlayerStatusReadyToPlay' state.";
+ jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('cordova-plugin-media.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:errcode message:errMsg]];
}
}
// ignore if no media playing
expect(position).toBeLessThan(10);
media1.stop();
media1.release();
+ context.done = true;
done();
}, failed.bind(null, done, 'media1.getCurrentPosition - Error getting media current position'),context);
}, 4000);
expect(true).toBe(true);
media1.stop();
media1.release();
+ context.done = true;
done();
}
};
media1.play();
}, ACTUAL_PLAYBACK_TEST_TIMEOUT);
- it("media.spec.26 should not crash or throw when setting the volume right after creating the media", function () {
+ it("media.spec.26 should not crash or throw when setting the volume right after creating the media", function (done) {
//bb10 dialog pops up, preventing tests from running
if (cordova.platformId === 'blackberry10') {
pending();
}
- var context = this;
var mediaFile = WEB_MP3_FILE;
var media = null;
- var successCallback = function () { };
- var statusChange = function () { };
-
expect(function () {
- media = new Media(mediaFile, successCallback, failed.bind(null, successCallback, 'Error creating Media object. Media file: ' + mediaFile, context), statusChange);
+ media = new Media(mediaFile);
media.setVolume('0.5');
}).not.toThrow();
- if (media) {
- media.release();
+
+ // if there is no exception or crash in 3 seconds, the spec is completed
+ setTimeout(function () {
+ if (media) {
+ media.release();
+ done();
+ }
+ }, 3000);
+ });
+
+ it("media.spec.27 should call success or error when trying to stop a media that is in starting state", function (done) {
+ //bb10 dialog pops up, preventing tests from running
+ if (!isAudioSupported || cordova.platformId === 'blackberry10') {
+ pending();
}
+
+ var mediaFile = WEB_MP3_FILE;
+ var media = null;
+ var context = this;
+ var beenStarting = false;
+ var safeDone = function () {
+ if (!context.done) {
+ media.release();
+ context.done = true;
+ done();
+ }
+ };
+
+ var errorCallback = jasmine.createSpy('errorCallback').and.callFake(function (e) {
+ expect(beenStarting).toBe(true);
+ safeDone();
+ });
+ var successCallback = function () {
+ expect(true).toBe(true);
+ safeDone();
+ };
+ var statusChange = function (s) {
+ if ((s == Media.MEDIA_STARTING) && !context.done) {
+ beenStarting = true;
+ media.stop();
+ } else if (s == Media.MEDIA_RUNNING) {
+ // Some plugin implementations may skip "Starting" state
+ // so we'll also try to call stop in "Running" state,
+ // but in this case we should check that the "Starting" state wasn't really reached,
+ // otherwise it would mean that the previous media.stop() call has been ignored
+ expect(beenStarting).toBe(false);
+ media.stop();
+ }
+ };
+
+ media = new Media(mediaFile, successCallback, errorCallback, statusChange);
+ media.play();
});
+
});
};