Solution to uniapp sound playback error: 1. Open the corresponding code file, and then directly execute the object play method to replace the original src path; 2. Update the development tool version.
The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, DELL G3 computer.
uni-app Voice file playback problem, innerAudioContext cannot be destroyed! ! !
##uni-app Voice createInnerAudioContext object cannot be destroyed and crashes! ! ! I found that the voice could not be played during packaging today, so I looked for the reason. I remembered that this problem had been dealt with, so I quickly found the problem. I used the wrong project and used the original one for packaging. This error It's really unforgivable. I would like to record the error that the voice cannot be played today. Voice playback is created using the built-in uni.createInnerAudioContext();. When playing, an error is reported and crashes. Post the code, this is how I wrote it. When the current method is called, paste the code directly. This is wrong. Don't copy it directly, brother.<script> const innerAudioContext = uni.createInnerAudioContext();data() { return {```}; }, methods: { hechengAudio(audioPram) { // innerAudioContext.stop(); var dd = audioPram.replace(/<\/?.+?>/g, ""); audioPram = dd.replace(/ /g, ""); //dds为得到后的内容 if (audioPram != this.startAudio) { this.startPage = false; } var url = this.getMp3 + 'cuid=' + uni.getSystemInfoSync().version + '&lan=zh&ctp=1&tok=' + this.$token() + '&tex=' + audioPram + '&vol=5&per=0&spd=6&pit=5&aue=3'; // console.log(JSON.stringify(resSave)); console.log(url); // #ifdef APP-PLUS // 下面这两句是重点, 拿本本记下.............. if (innerAudioContext != undefined) { innerAudioContext.stop(); } innerAudioContext = uni.createInnerAudioContext(); // 上面这两句是重点, 拿本本记下.............. this.pageValue = this.value; console.log('src是空的吗 -----------' + url) innerAudioContext.stop(); innerAudioContext.src = url; innerAudioContext.play();// if (url != '') {// innerAudioContext.play();// } else {// console.log('src是空的吗 -----------' + url)// uni.showToast({// title: 'src是空的 不能执行',// mask: true,// duration: 2000,// icon: "none"// });// // return// } innerAudioContext.onPlay(() => { console.log('开始播放') }) innerAudioContext.onStop(() => { console.log('i am onStop') //播放停止,销毁该实例 // innerAudioContext.stop() }) innerAudioContext.onEnded(() => { console.log('i am onEnded') //播放结束,销毁该实例 // innerAudioContext.stop() console.log('已执行destory()') }) innerAudioContext.onError((res) => { console.log(result.errMsg) console.log(result.errCode) // innerAudioContext.stop() }) // #endif // #ifdef MP-WEIXIN var that = this; uni.downloadFile({ url: url, success(res) { if (innerAudioContext != undefined) { innerAudioContext.stop(); } innerAudioContext = uni.createInnerAudioContext(); that.pageValue = that.value; innerAudioContext.src = res.tempFilePath; innerAudioContext.play(); innerAudioContext.onPlay(() => { console.log('开始播放') }) innerAudioContext.onStop(() => { console.log('i am onStop') innerAudioContext.stop() //播放停止,销毁该实例 innerAudioContext.stop() }) innerAudioContext.onEnded(() => { console.log('i am onEnded') //播放结束,销毁该实例 innerAudioContext.stop() console.log('已执行destory()') }) innerAudioContext.onError((res) => { console.log(result.errMsg) console.log(result.errCode) innerAudioContext.stop() }) } }) // #endif }, }, }</script>When you see the two lines of code above, remember not to destroy it, just execute the object play method directly. This method uses an object, which will replace the original src path by default and can be played directly.Another reason is that the version of the development tool is too old. My current version is 1.6.2. Mainly This version of the process has fewer problems. The following code can be copied
<script> const innerAudioContext = uni.createInnerAudioContext();data() { return {```}; }, methods: { hechengAudio(audioPram) { // innerAudioContext.stop(); var dd = audioPram.replace(/<\/?.+?>/g, ""); audioPram = dd.replace(/ /g, ""); //dds为得到后的内容 if (audioPram != this.startAudio) { this.startPage = false; } var url = this.getMp3 + 'cuid=' + uni.getSystemInfoSync().version + '&lan=zh&ctp=1&tok=' + this.$token() + '&tex=' + audioPram + '&vol=5&per=0&spd=6&pit=5&aue=3'; // console.log(JSON.stringify(resSave)); console.log(url); // #ifdef APP-PLUS this.pageValue = this.value; console.log('src是空的吗 -----------' + url) innerAudioContext.stop(); innerAudioContext.src = url; innerAudioContext.play(); innerAudioContext.onPlay(() => { console.log('开始播放') }) innerAudioContext.onStop(() => { console.log('i am onStop') //播放停止,销毁该实例 // innerAudioContext.stop() }) innerAudioContext.onEnded(() => { console.log('i am onEnded') //播放结束,销毁该实例 // innerAudioContext.stop() console.log('已执行destory()') }) innerAudioContext.onError((res) => { console.log(result.errMsg) console.log(result.errCode) // innerAudioContext.stop() }) // #endif // #ifdef MP-WEIXIN var that = this; uni.downloadFile({ url: url, success(res) { if (innerAudioContext != undefined) { innerAudioContext.stop(); } innerAudioContext = uni.createInnerAudioContext(); that.pageValue = that.value; innerAudioContext.src = res.tempFilePath; innerAudioContext.play(); innerAudioContext.onPlay(() => { console.log('开始播放') }) innerAudioContext.onStop(() => { console.log('i am onStop') innerAudioContext.stop() //播放停止,销毁该实例 innerAudioContext.stop() }) innerAudioContext.onEnded(() => { console.log('i am onEnded') //播放结束,销毁该实例 innerAudioContext.stop() console.log('已执行destory()') }) innerAudioContext.onError((res) => { console.log(result.errMsg) console.log(result.errCode) innerAudioContext.stop() }) } }) // #endif }, }, }</script>Recommended: "
uniapp tutorial"
The above is the detailed content of How to solve the problem of sound playing error in uniapp. For more information, please follow other related articles on the PHP Chinese website!

The article discusses debugging strategies for mobile and web platforms, highlighting tools like Android Studio, Xcode, and Chrome DevTools, and techniques for consistent results across OS and performance optimization.

The article discusses debugging tools and best practices for UniApp development, focusing on tools like HBuilderX, WeChat Developer Tools, and Chrome DevTools.

The article discusses end-to-end testing for UniApp applications across multiple platforms. It covers defining test scenarios, choosing tools like Appium and Cypress, setting up environments, writing and running tests, analyzing results, and integrat

The article discusses various testing types for UniApp applications, including unit, integration, functional, UI/UX, performance, cross-platform, and security testing. It also covers ensuring cross-platform compatibility and recommends tools like Jes

The article discusses common performance anti-patterns in UniApp development, such as excessive global data use and inefficient data binding, and offers strategies to identify and mitigate these issues for better app performance.

The article discusses using profiling tools to identify and resolve performance bottlenecks in UniApp, focusing on setup, data analysis, and optimization.

The article discusses strategies for optimizing network requests in UniApp, focusing on reducing latency, implementing caching, and using monitoring tools to enhance application performance.

The article discusses optimizing images in UniApp for better web performance through compression, responsive design, lazy loading, caching, and using WebP format.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Zend Studio 13.0.1
Powerful PHP integrated development environment