gpt4 book ai didi

javascript - Cordova 和 HTML5 在播放声音时的差异

转载 作者:行者123 更新时间:2023-12-03 10:38:24 25 4
gpt4 key购买 nike

尝试在 iOS 设备/模拟器上以 HTML5 和 Cordova 播放声音时,得到不同的结果。它工作正常,并且在移动浏览器中运行 HTML5 时我总是有声音对象。 iOS 模拟器中未定义声音对象(因此我无法播放它)。

    SC.initialize({
client_id: 'MYIDGOESHERE'
});

var soundCloudUrl = '';

//Grab the artist detail and then grab the soundcloud details
$http.post(BASE_URL + 'artistdetail', {band_id: band_id}).
success(function (data, status, headers, config) {

$scope.artistDetails = data;
soundCloudUrl = "https://soundcloud.com/en-flux/jomox-rode-drop";
}).
error(function (data, status, headers, config) {
$scope.showAlert("Oops", "Try again later.");
}).then(function () {
$http.get('http://api.soundcloud.com/resolve.json?url=' + soundCloudUrl + '&client_id=MYCLIENTID').
success(function (data) {
console.log(data);
$scope.soundcloudData = data;
SC.stream(data.uri, function (sound) {
console.log(sound); //THIS IS THE LOG THAT DIFFERS
$scope.playTrack = function () {
sound.play();
$scope.playing = true;
}
$scope.pauseTrack = function () {
sound.pause();
$scope.playing = false;
}
$scope.leaveDetail = function (state) {
if (state == 'stop') {
sound.stop();
} else {
sound.pause();
}
$scope.playing = false;
}

});
}).
error(function (data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});

});

所以,在 iOS 中,我对声音的 console.log 感到错误,但直接在浏览器中的 HTML5 中,一切都很好......有什么想法吗?

最佳答案

你的 promise 链很长。也许只是将其分解并逐步处理所有事情。你可能已经这样做了,但我知道随着我的锁链/回调 hell 开始增长,东西坏了,我必须回去追踪。

设置和初始化:

// Source to the Soundcloud channels I'm requesting
$scope.scdata = soundCloud.soundCloudData;

// Initialize the Soundcloud API onload of the controller
soundCloud.initialize();

// Currently not being used will be (didn't work when I declared it in the promise)
$scope.player = null;

获取 SC 特定信息的用户交互:

// Click in the element to get it's object and grab the SC id
$scope.load = function(){

// Create the request url (/user + '-userID'/, /channels... )
var url = '/tracks/' + this.m.id;

// GET request to Soundcloud
SC.stream(url).then(function(player){
$scope.show();
$scope.player = player;
});
};

然后我为我的播放器创建了函数:

$scope.player.pause();
$scope.player.play();
};

// Click play to load the track
$scope.play = function () {
$scope.player.play();
};

// Click play to close the track
$scope.stop = function () {
$scope.player.pause();
};

在我开始工作后,我重构了错误、成功消息......

关于javascript - Cordova 和 HTML5 在播放声音时的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28892316/

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