gpt4 book ai didi

javascript - 媒体插件错误代码 : 1

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:54 24 4
gpt4 key购买 nike

我无法使用 Cordova Media 插件播放本地声音。

我在我的 platforms\android\res\xml\config.xml 这里有正确的选项...

<content src="index.html" />
<access origin="*" />
<preference name="loglevel" value="DEBUG" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="Media">
<param name="android-package" value="org.apache.cordova.media.AudioHandler" />
</feature>
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
</feature>

...以及我的 AndroidManifest.xml 中的权限选项...

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

但是,当我尝试播放声音时,我什么也没得到:

enter image description here

注意:我使用的是 Apache Cordova 3.3.0

最佳答案

设法弄清楚最后你必须引用相对于 window.location.pathname 的文件路径,因为当通过 Apache Cordova 运行时根是 file:///android_asset/www/ 所以必须像这样引用声音 /android_asset/www/path/to/a/sound.mp3

这是我的完整解决方案:

var audio = {
root: '',
localPath: '/assets/sounds/',
manifest: {
bang: 'bang.mp3',
boom: 'boom.mp3',
splat: 'splat.mp3',
splash: 'splash.mp3'
},
sounds: {},
parse: function () {
var p = window.location.pathname;
this.root = p.substring(0, p.lastIndexOf('/')) + this.localPath;
console.log(this.root);
for (var sound in this.manifest) {
var src = this.root + this.manifest[sound];
console.log('Getting sound: ' + src);
this.sounds[sound] = (typeof Media !== 'undefined') ? new Media(src) : new Audio(src);
console.log('Created sound:');
$('#sounds').append($('<li></li>').html(src));
}
}
};
audio.parse();

例如,我的 index.html 位于我的根目录中,从我的 Angular 来看,它本质上是 ./(www 文件夹)。

我所有的声音都在两个子文件夹 ./assets/sounds/ 中。

在我的 PC 上托管应用程序时 window.location.pathname 显示为 /:

enter image description here

但是,当托管在我的移动设备上时,它是:

enter image description here

关于javascript - 媒体插件错误代码 : 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21244052/

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