You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2022/04/27 16:00:44 UTC

[cordova-plugin-media] 01/03: Add durationUpdate callback

This is an automated email from the ASF dual-hosted git repository.

erisu pushed a commit to branch duration-callback
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-media.git

commit d630fed5e00e517064d7344f01e6a83748ba3bf9
Author: Buddy Reno <bu...@daveramsey.com>
AuthorDate: Thu Nov 15 13:46:07 2018 -0600

    Add durationUpdate callback
---
 README.md    |  5 +++++
 www/Media.js | 12 ++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 5f46e33..fe8f2dc 100644
--- a/README.md
+++ b/README.md
@@ -73,6 +73,8 @@ var media = new Media(src, mediaSuccess, [mediaError], [mediaStatus]);
 
 - __mediaStatus__: (Optional) The callback that executes to indicate status changes. It takes a integer status code. _(Function)_
 
+- __mediaDurationUpdate__: (Optional) the callback that executes when the file's duration updates and is available. _(Function)_
+
 __NOTE__: `cdvfile` path is supported as `src` parameter:
 ```javascript
 var my_media = new Media('cdvfile://localhost/temporary/recording.mp3', ...);
@@ -235,6 +237,9 @@ var timerDur = setInterval(function() {
 }, 100);
 ```
 
+#### Android Quirk
+Newer versions of android have aggressive routines that limit background processing. If you are trying to get duration while your app is in the background longer than roughly 5 minutes, you will get more consistent results by using the `mediaDurationUpdate` callback. 
+
 ## media.pause
 
 Pauses playing an audio file.
diff --git a/www/Media.js b/www/Media.js
index 9a5c60b..e36359a 100644
--- a/www/Media.js
+++ b/www/Media.js
@@ -37,9 +37,13 @@ var mediaObjects = {};
  * @param errorCallback         The callback to be called if there is an error.
  *                                  errorCallback(int errorCode) - OPTIONAL
  * @param statusCallback        The callback to be called when media status has changed.
- *                                  statusCallback(int statusCode) - OPTIONAL
+ *                                statusCallback(int statusCode) - OPTIONAL
+ *  
+ * @param durationUpdateCallback  The callback to be called when the duration updates.
+ *                                durationUpdateCallback(float duration) - OPTIONAL
+ * 
  */
-var Media = function (src, successCallback, errorCallback, statusCallback) {
+var Media = function (src, successCallback, errorCallback, statusCallback, durationUpdateCallback) {
     argscheck.checkArgs('sFFF', 'Media', arguments);
     this.id = utils.createUUID();
     mediaObjects[this.id] = this;
@@ -47,6 +51,7 @@ var Media = function (src, successCallback, errorCallback, statusCallback) {
     this.successCallback = successCallback;
     this.errorCallback = errorCallback;
     this.statusCallback = statusCallback;
+    this.durationUpdateCallback = durationUpdateCallback;
     this._duration = -1;
     this._position = -1;
     exec(null, this.errorCallback, 'Media', 'create', [this.id, this.src]);
@@ -246,6 +251,9 @@ Media.onStatus = function (id, msgType, value) {
             break;
         case Media.MEDIA_DURATION:
             media._duration = value;
+            if (media.durationUpdateCallback) {
+                media.durationUpdateCallback(value);
+            }
             break;
         case Media.MEDIA_ERROR:
             if (media.errorCallback) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org