arielfaur / ionic-audio

An audio player for Ionic 3 and Angular 4. Works with HTML 5 audio or native audio using Cordova Media plugin.
http://arielfaur.github.io/ionic-audio/2.0/index.html
MIT License
321 stars 163 forks source link

preload metadata is not preloading tracks with local files - It works only on streaming #210

Open garalimedkarim opened 5 years ago

garalimedkarim commented 5 years ago

Hi everybody,

I'm working on an Ionic 3 App which playing both streaming and local files, So, the play staff is "OK" but with local files the preload:"metadata" is not preloading my tracks (duration, etc ...),

I'm asking if there is a way to force preload for local files. Thanks

        let myPath = this.file.externalRootDirectory+track.fullPath.substr(1);
        let newTrack = {
          src: myPath,
          artist: 'John Mayer',
          title: "myTitle",
          preload: 'metadata'
        }
        this.myTracks.push(newTrack); 

For My Exemple it's playing, but not preloading data, So the data are not loaded until I click "play" for this track. :/ Can someone help me ?

garalimedkarim commented 5 years ago

Hey Community I found the solution, You have just to choose automatically, if the src of the track is a remote "https://...", if must be managed by "WebAudioProvider" in this case the duration will load correctly for remote, and for local files it must be managed by "CordovaMediaProvider" (the duration doesn't work until we click play but it isn't a big matter )

So, the conclusion the provider must be used automatically depending on track ( streaming | local )

export function defaultAudioProviderFactory() {
    return window.hasOwnProperty('cordova') && window.hasOwnProperty('Media') ? new CordovaMediaProvider() : new WebAudioProvider();
}