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/28 01:46:46 UTC

[cordova-plugin-media] branch master updated: feat: add durationUpdate callback (#197)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 177a56b  feat: add durationUpdate callback (#197)
177a56b is described below

commit 177a56ba67f3b6f7f0019a70b525099fce8d2eb3
Author: Buddy Reno <th...@gmail.com>
AuthorDate: Wed Apr 27 20:46:42 2022 -0500

    feat: add durationUpdate callback (#197)
    
    * Add durationUpdate callback
    * Update README.md
    
    Co-Authored-By: BuddyLReno <bu...@daveramsey.com>
    Co-authored-by: Buddy Reno <bu...@daveramsey.com>
    Co-authored-by: Jan Piotrowski <pi...@gmail.com>
    Co-authored-by: エリス <er...@users.noreply.github.com>
---
 README.md    |  6 ++++++
 www/Media.js | 12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 5f46e33..0f20d4b 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,10 @@ var timerDur = setInterval(function() {
 }, 100);
 ```
 
+#### Android Quirk
+
+Newer versions of Android have aggressive routines that limit background processing. If you are trying to get the duration while your app is in the background longer than roughly 5 minutes, you will get more consistent results by using the [`mediaDurationUpdate` callback of the constructor](#parameters). 
+
 ## media.pause
 
 Pauses playing an audio file.
diff --git a/www/Media.js b/www/Media.js
index 9a5c60b..0eda5cd 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