gpt4 book ai didi

ios - Cordova 媒体插件 setVolume() 不工作

转载 作者:可可西里 更新时间:2023-11-01 03:34:09 24 4
gpt4 key购买 nike

这是我的播放功能:如您所见,我在多个位置将 Volume() 设置为 0。这完全没有效果。我试过也设置为 0.8、0.2,没关系,它不会起作用。我也尝试过非字符串值,这并不重要,因为该值在 Obj-C 模块内部被转换为浮点值。我还使用 NSLogged 来确保值被正确传递,并且确实如此。

使用 iPad iOS 9.2 进行测试 | Cordova 6.2 | Cordova 媒体插件 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);
}

任何帮助或指导都会很棒。

最佳答案

以下示例代码运行良好,并在 Android 和 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));
}

示例应用程序可以从 github page 下载。 .确保添加媒体和设备插件以进行相同的测试。更多信息可以在示例应用程序的自述文件中找到。希望对您有所帮助。

关于ios - Cordova 媒体插件 setVolume() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38059052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com