Note that there are some explanatory texts on larger screens.

plurals
  1. POMedia.getduration returns -1
    primarykey
    data
    text
    <p>I am trying to get the duration of the audio files. For that I am using the following code:</p> <pre><code>$.fntReproducir=function(){ //obtenemos una instancia del elemento que contiene la info. de cancion a reproducir var $objContenedorCancion=$('#olCanciones').children().eq(iCancionActual); //obtenemos la ruta del archivo que se va a reproducir y se lo asignamos //al source del audio player de HTML5 objReproductor = new Media($objContenedorCancion.attr('rel'), stopAudio, null); //var timerDur = setInterval(GetCurrPosition, 1000); //desmarcamos cualquier cancion en la lista (si es que estuviese marcada alguna) $('#olCanciones li').removeClass('clsSeleccionado'); //marcamos en la lista la cancion que vamos a reproducir $objContenedorCancion.addClass('clsSeleccionado'); meState = myMediaState.play //reproducir la cancion con el metodo play objReproductor.play(); //PlayMusic(objReproductor); $('#lblDuracion').find('span').text('enters'); // Play audio if (objReproductor) { //objReproductor.play(); //document.getElementById('PlayStatusID').innerHTML = "&lt;p&gt;&lt;/p&gt;Status: playing..."; $('#lblDuracion').find('span').text('enters2'); //setButtonState(myMediaState.playback); // Update media position every second clearProgressTimmer(); $('#lblDuracion').find('span').text('enters4'); progressTimmer = setInterval(function () { // get my_audio position $('#lblDuracion').find('span').text('enters5'); objReproductor.getCurrentPosition( // success callback function (position) { //document.getElementById('lblCancion').innerHTML = "&lt;p&gt;&lt;/p&gt;Status: enters "; $('#lblDuracion').find('span').text('enters8'); if (position &gt;= 0){ $('#lblDuracion').find('span').text('enters6'); $('#lblEstado').find('span').text(position); }else { $('#lblEstado').find('span').text('0 sec'); } }, // error callback function (e) { $('#lblEstado').find('span').text('0 sec' + e); }); $('#lblDuracion').find('span').text(objReproductor.getDuration()); //$('#lblEstado').find('span').text(count); }, 1000); } $('#btnPausar').val('Play'); $('#btnPausar').find('img').attr('src','img/pause.png'); //$('#lblDuracion').find('span').text(objReproductor.getDuration()); //ocultamos suavemente los datos de la cancion anterior $('#divInfoCancion').find('label').stop(true.true).animate({ opacity: 0 },function(){ //obtenemos una instancia del elemento que contiene los datos de la cancion var $objContenedorCancion=$('#olCanciones').children().eq(iCancionActual); //actualizamos la informacion de la cancion que se esta reproduciendo //duracion total //nombre de la cancion //$('#lblCancion').find('span').text($objContenedorCancion.find('strong').text()); $('#lblCancion').text($objContenedorCancion.find('.li_song').text()); //artista //$('#lblArtista').find('span').text($objContenedorCancion.find('em').text()); $('#lblArtista').text($objContenedorCancion.find('.li_artist').text()); //tiempo transcurrido //$('#lblEstado').find('span').text('00:00'); //imagen $('#current_img').attr('src',$objContenedorCancion.find('img').attr('src')); //mostramos suavemente la info. de la nueva cancion $(this).stop(true,true).animate({ opacity: 1 }); }); </code></pre> <p>I saw in some forums that setInterval was mandatory to use getDuration, that is why I use it but it is not giving me any result. The file is loaded well because I can hear it and it enters in GetCurrentPosition because the text "duration = -1" appears so it is clear that is giving -1 value. How can I make to get the correct duration value?</p> <p>EDIT </p> <p>I put more code and also add getCurrentPosition witch is not working. I put different $('#lblDuracion').find('span').text('enters'); with different numbers to see what was the value that appears in 'lblDuracion' and it is 'enters5' but it also passes from the line $('#lblEstado').find('span').text(objReproductor.getDuration()); that returns -1.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload