katspaugh / wavesurfer.js

Audio waveform player
https://wavesurfer.xyz
BSD 3-Clause "New" or "Revised" License
8.78k stars 1.63k forks source link

issue on iphone when using ajax to load song #1450

Closed jpbm18 closed 3 years ago

jpbm18 commented 6 years ago

I am using ajax to bring peak data into wavesurfer. On my laptop, all works as expected. Wavesurfer is able to load peak data and song begins playing when wavesurfer.play is initiated. But on my iphone, the waveform loads but won't begin playing until I press play.

I saw other posts describing a similar issue, but was unclear whether these issues were because of an ajax call. If I do the load and play outside of ajax, the song will start playing on my iphone without extra click.

When wavesurfer.play is initiated, I addClass('active') to a play button. On my iphone, even though the music doesn't start when the song loads, the addClass('active') does occur. Which to me says the wavesurfer.play is happening. So not sure why I need to press the play button in order for the song to actually play.

I'm using wavesurfer 2.0.6. My iphone is running iOS 11.4.1. Thanks for any thoughts you might have. Below is my code -

//THE AJAX CALL TO GET THE PEAKS DATA
$.ajax({
            url: 'peaks.php',
            type: "POST",
            data: ({songtitle: songtitle}),
            success: function(data){
            var peaks = JSON.parse(data)
            wavesurfer.load(songplaying, peaks, 'none');
            };
        });

//PLAY SONG AND CHANGE PLAY BUTTON TO ACTIVE
wavesurfer.on('ready', function () {
            wavesurfer.play();
            playButton.addClass('active');
});

//WAVEFORM PARAMETERS
var wavesurfer = WaveSurfer.create({
    container: '#waveform',
    hideScrollbar: 'true',
    height: '56',
    waveColor: '#aaabad',
    barWidth: 1,
    normalize: 'true',
    progressColor: '#2b2f33',
    backend: 'MediaElement',
    responsive: 'true'
});   
thijstriemstra commented 5 years ago

the waveform loads but won't begin playing until I press play.

ios and safari require a click to start wavesurfer.js (e.g. audiocontext).

jpbm18 commented 5 years ago

The issue I'm having is I need to click twice. I click once to load waveform data, using ajax call. The waveform loads, then I need to click a second time to play the file. If I don't use an ajax call to get waveform data, the song will start playing after only one click. Not sure why the ajax call would cause a need for a second click. Wonder if others experience similar behavior.

15838028035 commented 5 years ago

hi, is there a java demo for get peaks,

cloud you share your php demo for get peaks.

15838028035 commented 5 years ago

@jpbm18 cloud you share you demos ?

jpbm18 commented 5 years ago

Yes, will share demos. Will post as soon as I can.

15838028035 commented 5 years ago

@jpbm18 when i load big files from server , server generate big peaks,

it will be long time to load files, the memory up to height, it's not what i wanted , do you have test it ?

entonbiba commented 3 years ago

you may have a look here for ios safari playing wavesurfer https://www.entonbiba.com/lab/ios2.html