Giter VIP home page Giter VIP logo

Comments (10)

engr-Eghbali avatar engr-Eghbali commented on July 17, 2024 1

Done, the bug remains.

from cordova-plugin-media.

janpio avatar janpio commented on July 17, 2024 1
  1. You didn't mention before that you are working with a file that was just created with captureAudio.
  2. Why should this make a difference? The relevant part here is that you create a new Media object with a path to a certain file. If this plugin doesn't actually read the file data until you call play() - then it just can't know the duration. You will have to check this plugin's code to understand when it is reading the file to get the duration.

If the current state then is not what you want, create a new issue and suggest this to be implemented or best create a PR yourself.

from cordova-plugin-media.

zhanghuanchong avatar zhanghuanchong commented on July 17, 2024 1

I have a solution to get the correct duration after recording on iOS:

After below line:

// no callback - that will happen in audioRecorderDidFinishRecording

Add:

        [self prepareToPlay:audioFile withId:mediaId];
        double duration = round(audioFile.player.duration * 1000) / 1000;
        [self onStatus:MEDIA_DURATION mediaId:mediaId param:@(duration)];

from cordova-plugin-media.

janpio avatar janpio commented on July 17, 2024

What platform? What platform version?
What device were you testing on? What OS version was that running?
What version of the plugin?

What is MEDIA? Do you mean Media?

from cordova-plugin-media.

engr-Eghbali avatar engr-Eghbali commented on July 17, 2024

@janpio
platform android(v7.0.0 ) on "HTC One A9" & "Samsung galaxy A7" , both android nougat and 5.0.2 plugin version.
sorry for mistake, yes Media is true. (include recorded voice and video in this case).

from cordova-plugin-media.

janpio avatar janpio commented on July 17, 2024

Then first update your cordova-android to the current version 7.1.1 to make sure this is not fixed already.

from cordova-plugin-media.

janpio avatar janpio commented on July 17, 2024

Documentation says:

media.getDuration
Returns the duration of an audio file in seconds. If the duration is unknown, it returns a value of -1.

Is it possible that the data is actually not available before play was executed? When is the file actually requested/loaded?

from cordova-plugin-media.

engr-Eghbali avatar engr-Eghbali commented on July 17, 2024

I tried different ways,data should not available "onSuccess"? working version is like:

 navigator.device.capture.captureAudio(onSuccess, onError, options);

   function onSuccess(mediaFiles) {
      var  path,recordedVoice,stat,interval,;
     
       path = mediaFiles[0].fullPath;
       recordedVoice = new Media(path, function(){console.log("well played!")}, function(e){console.log("error:"+e)},function(status){stat=status});
      
       recordedVoice.play();
       recordedVoice.pause();

         document.getElementById("playBTN").addEventListener("click",()=>{
           var constant=100/(recordedVoice.getDuration()*10);
///etc..

from cordova-plugin-media.

engr-Eghbali avatar engr-Eghbali commented on July 17, 2024

Yes, I think that's a need, thanks a lot.

from cordova-plugin-media.

pagano avatar pagano commented on July 17, 2024

I have a solution to get the correct duration after recording on iOS:

After below line:

// no callback - that will happen in audioRecorderDidFinishRecording

Add:

        [self prepareToPlay:audioFile withId:mediaId];
        double duration = round(audioFile.player.duration * 1000) / 1000;
        [self onStatus:MEDIA_DURATION mediaId:mediaId param:@(duration)];

Nice catch zhang! I don't know how to do it, but a pull request for this would be great

from cordova-plugin-media.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.