You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by al...@apache.org on 2016/08/29 09:17:42 UTC
cordova-plugin-media git commit: CB-11757 (ios) Error out if trying
to stop playback while in a wrong state
Repository: cordova-plugin-media
Updated Branches:
refs/heads/master 0405a2ee2 -> 22f99bcc8
CB-11757 (ios) Error out if trying to stop playback while in a wrong state
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/commit/22f99bcc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/22f99bcc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/22f99bcc
Branch: refs/heads/master
Commit: 22f99bcc8f7ab98d3115fb06f7deb0abfab8d84c
Parents: 0405a2e
Author: Alexander Sorokin <al...@akvelon.com>
Authored: Fri Aug 26 12:48:50 2016 +0300
Committer: Alexander Sorokin <al...@akvelon.com>
Committed: Mon Aug 29 10:49:44 2016 +0300
----------------------------------------------------------------------
src/ios/CDVSound.h | 1 +
src/ios/CDVSound.m | 5 +++-
tests/tests.js | 64 ++++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 61 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/22f99bcc/src/ios/CDVSound.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVSound.h b/src/ios/CDVSound.h
index 2f1d0e0..3f123b0 100644
--- a/src/ios/CDVSound.h
+++ b/src/ios/CDVSound.h
@@ -22,6 +22,7 @@
#import <Cordova/CDVPlugin.h>
enum CDVMediaError {
+ MEDIA_ERR_NONE_ACTIVE = 0,
MEDIA_ERR_ABORTED = 1,
MEDIA_ERR_NETWORK = 2,
MEDIA_ERR_DECODE = 3,
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/22f99bcc/src/ios/CDVSound.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVSound.m b/src/ios/CDVSound.m
index 98de46f..09d3587 100644
--- a/src/ios/CDVSound.m
+++ b/src/ios/CDVSound.m
@@ -495,7 +495,10 @@
}];
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
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/22f99bcc/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index d627221..fa283d9 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -403,6 +403,7 @@ exports.defineAutoTests = function () {
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);
@@ -436,6 +437,7 @@ exports.defineAutoTests = function () {
expect(true).toBe(true);
media1.stop();
media1.release();
+ context.done = true;
done();
}
};
@@ -444,27 +446,73 @@ exports.defineAutoTests = function () {
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();
});
+
});
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org