Cordova Media object loads sound and stops playing after 29 times of load.

5 posts, 0 answers
  1. Pearson
    Pearson avatar
    13 posts
    Member since:
    Dec 2012

    Posted 13 Mar 2013 Link to this post

    Hi,
    I am using cordova Media object for playing audio files in my HTML5 App.  All the audio files are playing well in the app. However, I am having trouble with the audios after playing them multiple times in the same screen. When the audio in my app stops playing, all my other apps in the device also not playing the audio. To find out the issue, I created an html file with a button to load an audio(same) for multiple times and I found that, it was playing till 29 times(click count) of loading and playing. After that, the audio stops playing in the app. 

    User action:
    1. Sound does not play in all other apps, if i minimize the current app after the issue. 
    2. If i close my app and restart the same, the audio plays fine but only for 29 times.

     What could be the reason and can you please help me on this issue?

    Expecting your early reply

  2. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 13 Mar 2013 Link to this post

    Hello,

     Could you please share more details about the issue? What device and OS version are you running your app on? Have you tried with a different sound file, even one in another format?

     Also, would it be possible for you to share the code that demonstrates this behavior so that we can debug it locally?

    Regards,
    Yavor Georgiev
    the Telerik team

    Share feedback and vote for features on our Feedback Portal.
    Want some Kendo UI online training - head over to Pluralsight.
  3. Pearson
    Pearson avatar
    13 posts
    Member since:
    Dec 2012

    Posted 13 Mar 2013 Link to this post

    Hi Yavor. Thanks you for your response.

    I tried with many devices as Samsung Galaxy 7 inch and 10 inch, Micromax 7 inch and 10 inch. The result was same in all the devices.

    The code that I used for playing is given below.

    document.addEventListener('deviceready', function(){
                    navigator.splashscreen.hide();
                    var __mediaPlayer = new MediaPlayer();
                    
                    var __count = 0;
                    var __playMedia = function(aEvent){
                        __count++;
                        __mediaPlayer.load("file:///android_asset/content/sound/testing.mp3");                    
                        __mediaPlayer.play();
                        $(".count").text(__count);
                    }
                    var _button = document.getElementById("testCase_1");
                    _button.addEventListener("touchend",__playMedia);
                }, false);
    ----------------
    And the MediaPlayer object that I used is given below. I used the same file that you had given in the sample Media example with some small changes.


    document.addEventListener("touchstart", function() {}, false);

    function MediaPlayer() {
    }

    MediaPlayer.prototype = {
        
    mediaContent : null,
    isPlaying : false,
        __audioLoop : false,    
    load: function(aSrc) {
    var that = this;
    that.mediaContent = new Media(aSrc, 
     function() {
     that.onMediaSuccess.apply(that, arguments);
     },
     function() {
     that.onError.apply(that, arguments);
     },
                                          function(){                                          
                                               that.onStatus.apply(that, arguments); 
                                          });        
    },
        
    onMediaSuccess: function() {
    if (!this.isPlaying) {
    this.mediaContent.release();
    }
    },
        
    onError: function(error) {
    var errorMessage = "code: " + error.code + "\n" +
      "message: " + error.message + "\n";
    },
        onStatus: function(aStatus){        
            if(aStatus==4 && __audioLoop==true){
                this.mediaContent.play();
            }
        },
        loop : function(aBoolean){
            __audioLoop = aBoolean;
        },
        
    play: function() {
            if(this.mediaContent != null){
       this.mediaContent.play();
       this.isPlaying = true;
            }
    },
        
    pause: function () {
            if(this.mediaContent != null){
       this.mediaContent.pause();
                this.isPlaying = false;
            }
    },
        
    stop: function () {
            if(this.mediaContent != null){
       this.mediaContent.stop();
       this.isPlaying = false;
            }
    }
    }

    Note: I was checking the apk in release mode. So I have used absolute path for the audio file.
    Please check the code given and help me with this issue.


  4. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    42 posts

    Posted 16 Mar 2013 Link to this post

    Hi there,

    Thank you for your feedback.

    We have carefully examined your case and it seems that after last Cordova update our sample is not working properly and the underlying operating systems resources are not released.

    So make sure that media.release() is called every time media playing  finishes.

    More information here: link

    Sorry for caused inconvenience, we will update our media sample as soon as possible.
    Please do not hesitate to contact us if you have any other issues.

    Kind regards,
    Ivan Ivanov
    the Telerik team

    Share feedback and vote for features on our Feedback Portal.
    Want some Kendo UI online training - head over to Pluralsight.
  5. Pearson
    Pearson avatar
    13 posts
    Member since:
    Dec 2012

    Posted 19 Mar 2013 Link to this post

    Thank you very much for your reply Ivan.

    Thant is the one thing that I have done currently and its working fine. I just called the media.release() before creating each new Media object. Then it worked fine.

    Anyway thank you for your valuable reply and expecting a lot from Icenium in future. Will get you back I have any other feedbacks.
Back to Top