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

Can't play again #185

Open zhudingshibai opened 6 years ago

zhudingshibai commented 6 years ago

I an using this for an ionic app. The mp3 file can only play once .

this is the console.log messages:

  1. play Loading track http://***/APP/DonkeyDonkey.mp3 Playing audio sample 'http://***/APP/DonkeyDonkey.mp3' Playing stream with AVPlayer & default rate Playing track http://***/APP/DonkeyDonkey.mp3 Finished playback Track finished Media with id 1e10e9b5-6b8e-b325-379f-e45b8377ff7d released Released track http://***/APP/DonkeyDonkey.mp3

  2. play again: Loading track http://***/APP/DonkeyDonkey.mp3 Will use resource 'http://***/APP/DonkeyDonkey.mp3' from the Internet. Audio error => track http://***/APP/DonkeyDonkey.mp3 [object Object] Loading track http://***/APP/DonkeyDonkey.mp3 Audio error => track http://***/APP/DonkeyDonkey.mp3 [object Object]


config:

from.tracks = [{ src: 'http://***' + encodeURI(from.arr_people.audio), artist: '', title: '', art: '', preload: 'metadata' }];


HTML : <audio-track #audio *ngFor="let track of tracks" [track]="track" (onFinish)="onTrackFinished($event)"> <ion-item style="background-color:rgb(117, 165, 236)" [hidden]='!playing'>

            <div item-content style="width:100%">
                <audio-track-progress-bar dark duration progress [audioTrack]="audio" [ngStyle]="{visibility: audio.completed > 0 ? 'visible' : 'hidden'}"></audio-track-progress-bar>
            </div>
        </ion-item>
    </audio-track>
arielfaur commented 6 years ago

Are you using the cordova plugin Media?

zhudingshibai commented 6 years ago

"cordova-plugin-media": "^3.0.1", "cordova-plugin-streaming-media": "^1.0.2",

I installed those two .

It's a bug of cordova plugin Media ?

zhudingshibai commented 6 years ago

I use WebAudioProvider now.

It can play again, but can't display pause and play button, it always refreshing...

arielfaur commented 6 years ago

Hmm it is hard to tell, it worked fine when I tested it back then. I will try to look into it whenever I find some spare time.

codinronan commented 6 years ago

cordova-plugin-media releases the track when they complete, even if ionic-audio doesn't. The simple solution is to just delete and re-create the track from the same source data once it completes. Most modern browsers will still have the entire song cached so you lose nothing in performance.

arielfaur commented 6 years ago

@codinronan That makes sense and explains why so many people are reporting the same issues. There are so many different use cases that it is hard to find one approach that works for all.

saumya04 commented 6 years ago

@codinronan Can you let me know how can I recreate the audio track after the track is released by the plugin. I mean which method to use to re-create it again?