2016-06-27 33 views
7

Ecco la mia funzione di riproduzione: Come potete vedere ho impostato SetVolume() in più posizioni su 0. Ciò non ha assolutamente alcun effetto. Ho provato a impostare anche a 0.8, 0.2, non importa non funzionerà. Ho anche provato un valore non stringa, che non ha importanza dal momento che il valore viene convertito in un valore float all'interno del modulo Obj-C. Ho anche NSLoggato per assicurarmi che il valore sia stato passato correttamente ed è così.Cordova Media Plugin setVolume() non funzionante

Test con iPad iOS 9.2 | Cordova 6.2 | Cordova Media Plugin 2.3.1.

play: function(src, seekTime) 
     { 
      App.Log.info('Playing audio source', src); 
      seekTime = seekTime ? seekTime : 0; 
      var obj = { 
       source: src, 
       startTime: new Date().getTime(), 
       seekTime: seekTime, 
       duration: 0, 
       preloadedNext: false, 
       audioSource: false 
      }; 
      obj.audioSource = new Media(src, function(event){ 
       $this.player().onAudioEnd(event, obj); 
      }, function(){ 
       //on error 
      }, function(status) 
      { 
       obj.audioSource.setVolume("0.0"); 
       if(status == 2){ 
        obj.audioSource.setVolume("0.0"); 
        obj.audioSource.seekTo(obj.seekTime * 1000); 
        obj.timer = setInterval(function(){ 
         obj.seekTime++; 
         obj.duration = obj.audioSource._duration; 
         if(obj.duration < 0){ 
          return; 
         } 
         if(obj.seekTime >= (obj.duration - $this.default.fadeTime)) 
         { 
          if(obj.preloadedNext){ 
           return; 
          } 
          obj.preloadedNext = true; 
          $this.player().preloadNext(obj); 
         } 
        }, 1000); 
       } 

      }); 
      obj.audioSource.setVolume("0.0"); 
      obj.audioSource.play(); 
      obj.audioSource.setVolume("0.0"); 
      obj.audioSource.seekTo(obj.seekTime * 1000); 
      console.log('Audio Source', JSON.stringify(obj)); 
      $this.playing.push(obj); 
} 

Qualsiasi aiuto o direzione sarebbe fantastico.

+0

considerano riempire un bug report su issues.cordova.io – jcesarmobile

+0

avete controllato la versione 'Android'? Non ho "mac" su di me per il momento, ma hai controllato che l'esecuzione sia correttamente inserita nel file "if" su https://github.com/apache/cordova-plugin-media/blob/master/src/ios /CDVSound.m#L260? – oak

+0

@ anthony.c ho provato il plug-in multimediale in un'app di esempio e setvolume funziona perfettamente. Ho pubblicato l'app di test nel mio github - https://github.com/gandhirajan/Cordova_Media. Controlla per vedere se è d'aiuto. Inoltre ho notato che la versione del plugin che hai citato è la 2.3.1 Ma se aggiungo il plugin usando il comando add, l'ultima versione disponibile è la 2.3.0 Spero tu stia provando nel ramo beta. Si prega di controllare il ramo principale e vedere se aiuta. Tienimi aggiornato – Gandhi

risposta

1

Il seguente codice di esempio funziona bene ed è testato in Android & dispositivi iOS:

index.html:

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8" /> 
     <meta name="format-detection" content="telephone=no" /> 
     <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 --> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
     <link rel="stylesheet" type="text/css" href="css/index.css" /> 
     <meta name="msapplication-tap-highlight" content="no" /> 
     <title>Hello World</title> 
    </head> 
    <body> 
     <button id="playMp3">Play MP3</button><br><br> 
     <button id="playMp3Mild">Play MP3 Mild</button><br><br> 
     <button id="playRemoteFile">Play Remote File</button> 

     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
    </body> 
</html> 

index.js:

document.addEventListener('deviceready', onDeviceReady, false); 

function onDeviceReady() { 
    document.querySelector("#playMp3").addEventListener("touchend", playMP3, false); 
    document.querySelector("#playMp3Mild").addEventListener("touchend", playMp3Mild, false); 
    document.querySelector("#playRemoteFile").addEventListener("touchend", playRemoteFile, false); 

}; 

function playMP3() { 
    var mp3URL = getMediaURL("sounds/button-1.mp3"); 
    var media = new Media(mp3URL, null, mediaError); 
    media.setVolume(1.0); 
    media.play(); 
} 

function playMp3Mild() { 
    var mp3URL = getMediaURL("sounds/button-1.mp3"); 
    var media = new Media(mp3URL, null, mediaError); 
    media.setVolume(0.1); 
    media.play(); 
} 

function playRemoteFile() { 
    var media = new Media("http://SERVER_IP:PORT/media/test.mp3"); 
    media.setVolume(0.1); 
    media.play(); 
} 

function getMediaURL(s) { 
    if(device.platform.toLowerCase() === "android") return "/android_asset/www/" + s; 
    return s; 
} 

function mediaError(e) { 
    alert('Media Error'); 
    alert(JSON.stringify(e)); 
} 

L'app di esempio può essere scaricata dal github page. Assicurati di aggiungere media e plug-in dispositivo per testare lo stesso. Maggiori informazioni possono essere trovate sul file README dell'applicazione di esempio. Spero che sia d'aiuto.

+1

@DavidNathan Ciao David, non capisco come questo problema sia correlato alla mia risposta – Gandhi

0

Non sono sicuro che questo risolva il problema, ma forse il volume non è impostato su zero perché il setVolume è chiamato troppo "presto". Potresti provare questo codice e segnalare eventualmente alcuni registri per perfezionare la mia soluzione?

play: function(src, seekTime) 
     { 
      App.Log.info('Playing audio source', src); 
      seekTime = seekTime ? seekTime : 0; 
      var obj = { 
       source: src, 
       startTime: new Date().getTime(), 
       seekTime: seekTime, 
       duration: 0, 
       preloadedNext: false, 
       audioSource: false 
      }; 
      obj.audioSource = new Media(src, function(event){ 
       $this.player().onAudioEnd(event, obj); 
      }, function(){ 
       //on error 
      }, function(status) 
      { 
       obj.audioSource.setVolume("0.0"); 
       if(status == 2){ 
        obj.audioSource.setVolume("0.0"); 
        obj.audioSource.seekTo(obj.seekTime * 1000); 
        obj.timer = setInterval(function(){ 
         obj.seekTime++; 
         obj.duration = obj.audioSource._duration; 
         if(obj.duration < 0){ 
          return; 
         } 
         if(obj.seekTime >= (obj.duration - $this.default.fadeTime)) 
         { 
          if(obj.preloadedNext){ 
           return; 
          } 
          obj.preloadedNext = true; 
          $this.player().preloadNext(obj); 
         } 
        }, 1000); 
       } 

      }); 
      //obj.audioSource.setVolume("0.0"); 
      obj.audioSource.play(); 
      setTimeout(function() { //try to set volume to 0 after 10 milliseconds 
       obj.audioSource.setVolume("0.0"); 
      }, 10); 
      setTimeout(function() { //try to seekTo after 1 second 
       obj.audioSource.seekTo(obj.seekTime * 1000); 
      }, 1000); 
      console.log('Audio Source', JSON.stringify(obj)); 
      $this.playing.push(obj); 
} 
+0

Apprezzo il fatto che tu abbia il tempo di rispondere, se noti sopra il blocco if (status == 2) {} ... Se status = 2 significa che il file audio si trova nello "Stato di esecuzione", quindi imposta il volume su quello punto dovrebbe permettermi di avere il controllo del volume anche se non è ancora pronto al di fuori di quel blocco. –

0

È possibile impostare un ritardo di disattivazione di un secondo per verificare se crea almeno un comportamento ritardato corretto? (Processo di eliminazione)

setTimeout(function() { 
obj.audioSource.setVolume("0.0"); 
}, 1000); 
Problemi correlati