Music player setting method and device based on H5 terminal
By transferring the audio processing logic to the WebAssembly module in the H5-side music player, and using Web Workers and Service Workers, issues such as performance, compatibility, offline support, and copyright protection are solved, achieving an efficient, safe, and rich music playback experience. .
Patent Information
- Application Number
- CN202410916779.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-07-10
AI Technical Summary
Existing H5-based music players have performance problems when processing large files or playing for long periods of time, poor browser compatibility, limited offline support, difficulty in achieving copyright protection, high resource consumption, and functional limitations.
By transferring audio processing logic to the WebAssembly module, using Web Workers to handle complex tasks, writing audio API adaptation layers, integrating multiple audio format support, using Service Workers to achieve offline playback and caching, using DRM and dynamic watermarks to protect copyright, and developing intelligent Resource management algorithm, utilizing hardware acceleration and advanced audio API to expand functionality.
Significantly improves the performance and user experience of the music player, enhances cross-browser compatibility, achieves reliable offline support, ensures safe transmission and playback of audio content, reduces resource consumption, and expands functionality.
Smart Images

Figure CN118466892B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a music player setting method, device and electronic device based on an H5 terminal. Background Art
[0002] H5-based music player refers to the music playback function implemented in web pages or web applications using HTML5 technology (mainly including HTML, CSS and JavaScript). With the popularization of HTML5 standards, developers can embed and control audio playback directly in the browser without relying on third-party plug-ins.
[0003] Such music players usually have the following basic functions:
[0004] Play and Pause: Control the audio playback status by calling the play() and pause() methods.
[0005] Track selection: Allows users to switch between multiple songs.
[0006] Progress control: The user can drag the progress bar to change the playback position, which usually involves the currentTime and duration properties.
[0007] Volume adjustment: Change the playback volume by modifying the volume property.
[0008] Playlist: Display and select multiple audio files for playback.
[0009] Event monitoring: For example, monitoring the ended event of an audio file to automatically play the next song.
[0010] The existing technology has the following main problems:
[0011] 1. Performance issues:
[0012] Although the H5 player works well in most cases, it may have performance issues when processing large files or long playback times, such as long buffering time, audio stuttering, etc. This is especially noticeable on low-end devices or when the network connection is unstable.
[0013] 2. Browser compatibility:
[0014] Although H5 has good cross-platform compatibility, different browsers have different levels of support for the H5 standard, which may cause some functions to not work properly in specific browsers. For example, Safari may not support certain audio formats and functions as well as Chrome or Firefox.
[0015] 3. Limited offline support:
[0016] H5 player mainly relies on network connection. Although Service Workers and caching technology can be used to achieve offline playback, there are still certain limitations, especially for offline storage and management of large files.
[0017] 4. Copyright protection issues:
[0018] The audio stream of the H5 player is usually directly exposed on the Internet and can be easily captured and downloaded, leading to copyright protection issues. Although DRM (digital rights management) technology can be used, its implementation is complex and may affect the user experience.
[0019] 5. Resource consumption:
[0020] Compared with native applications, H5 players consume more resources, especially for mobile devices, which may accelerate power consumption and cause the device to heat up.
[0021] 6. Functional limitations:
[0022] Although H5 players are feature-rich, they are still not as good as native apps. For example, H5 players may not be as good as native apps in terms of background playback, hardware acceleration, and audio effect processing.
[0023] The above problems become technical problems that need to be solved. Summary of the invention
[0024] In view of this, an embodiment of the present invention provides a music player setting method, device and electronic device based on the H5 terminal, which at least partially solves the problems existing in the prior art.
[0025] In a first aspect, an embodiment of the present invention provides a method for setting a music player based on an H5 terminal, including:
[0026] Transfer high-performance audio processing logic from JavaScript to WebAssembly module, write and compile Wasm code, integrate Wasm module in HTML5 player, and call Wasm module interface through JavaScript to process audio.
[0027] Use Web Workers to create independent worker threads to handle complex audio processing tasks. The main thread is responsible for UI rendering and user interaction, and audio processing tasks are executed in the background thread.
[0028] Write a unified audio API adaptation layer to encapsulate the differences in the implementation of audio APIs by different browsers, provide a consistent interface for players to call, and test and adjust the adaptation layer code;
[0029] Integrate support for multiple audio formats in the player to ensure that audio files can be played in different browser environments, and implement automatic format conversion. When uploading or playing audio files, they are automatically converted to the format supported by the current browser;
[0030] Use Service Workers to implement caching and offline playback of audio files, design block caching and breakpoint resume mechanisms, support caching and downloading of large files, and improve the stability of offline playback;
[0031] Use IndexedDB and File System Access API browser local storage technology to store and manage audio files, and realize the reading and management of audio files.
[0032] According to a specific implementation of the embodiment of the present disclosure, the method further includes:
[0033] Encrypt and protect audio content during playback, configure and deploy DRM servers, manage encryption keys and licenses, and ensure secure transmission and playback of audio content;
[0034] Embed dynamic watermarks in audio streams, design and implement dynamic watermark embedding and detection algorithms to ensure that the sound quality is not affected.
[0035] According to a specific implementation of the embodiment of the present disclosure, the method further includes:
[0036] Develop intelligent resource management algorithms to dynamically adjust the player's resource usage based on current system resources and audio playback conditions, optimize algorithm performance, and reduce unnecessary resource consumption;
[0037] Take advantage of the hardware acceleration capabilities of modern browsers to improve audio processing and rendering performance, adjust and optimize the audio processing flow, and reduce CPU load.
[0038] According to a specific implementation of the embodiment of the present disclosure, the method further includes:
[0039] Use Page Visibility API and Background Fetch API to ensure smooth audio playback in the browser background, dealing with the limitations of browser background tasks;
[0040] Use the advanced audio effect processing functions provided by the Web Audio API to develop equalizer and reverberation sound effect functions, and provide a user-adjustable sound effect parameter interface;
[0041] It provides visual audio waveform, synchronized lyrics display, and playlist management functions, allowing users to adjust the player interface and function settings according to their personal preferences.
[0042] According to a specific implementation of the embodiment of the present disclosure, the audio processing logic with high performance requirements is transferred from JavaScript to the WebAssembly module, the Wasm code is written and compiled, the Wasm module is integrated in the HTML5 player, and the interface of the Wasm module is called by JavaScript to perform audio processing, including:
[0043] Select a programming language that compiles to Wasm, and implement audio filtering, volume adjustment, and spectrum analysis in the selected programming language;
[0044] Mark the function with EMSCRIPTEN_KEEPALIVE macro, export the function to be called from JavaScript, and compile the source code into a Wasm file using the command emcc your_audio_processor.cs WASM=1 o your_audio_processor.wasm;
[0045] Use WebAssembly.instantiateStreaming to asynchronously load compiled Wasm files from JavaScript’s WebAssembly API;
[0046] Define the interface function of the Wasm module, which accepts and returns JavaScript-compatible data types, accesses and calls the previously exported audio processing function through the Wasm instance, and passes a reference or pointer to the audio data;
[0047] In HTML5 <audio>In a tag or a player built using the Web Audio API, listen for playback progress or data stream events. When audio data is available, call the processing function in the Wasm module to process the data, and then send the processed data back to the player to continue the playback process.
[0048] According to a specific implementation of the embodiment of the present disclosure, the use of Web Workers to create an independent work thread to handle complex audio processing tasks, the main thread is responsible for UI rendering and user interaction, and the audio processing task is executed in the background thread, including:
[0049] Create a new JavaScript file audioProcessor.js. This file will be the Web Worker script containing the audio processing logic.
[0050] In audioProcessor.js, write audio processing functions, including decoding, filtering, and applying special effects to audio data;
[0051] In the main HTML file, initialize a new Web Worker instance and specify the previously created audioProcessor.js as the entry script of the worker thread;
[0052] When audio data needs to be processed, the data is sent to the Worker thread through the postMessage method. In the Worker script, the message event is listened to to receive the instructions of the main thread. After the processing is completed, the result is returned to the main thread through postMessage. In the main thread, the message event of the Worker is listened to to receive and process the result of the audio processing.
[0053] According to a specific implementation of the embodiment of the present disclosure, the unified audio API adaptation layer is written to encapsulate the differences in the implementation of the audio API by different browsers, provide a consistent interface for the player to call, and test and adjust the adaptation layer code, including:
[0054] After determining the operation functions included in the player, set the API interface corresponding to the operation functions;
[0055] For each operation function, write adaptation code so that the same interface can be called in multiple browsers to achieve the expected behavior;
[0056] Feature detection is used to determine which audio API the current browser supports, and the implementation path is selected accordingly. For unsupported features, polyfill is used to simulate the implementation.
[0057] According to a specific implementation of the embodiment of the present disclosure, the method further includes:
[0058] Use JavaScript's canPlayType() method to detect browser support for a specific audio format. If not, use the Web Audio API to convert the audio format on the client side.
[0059] Register the Service Worker script in the main page or application shell, and use the fetch event listener and the ReadableStream feature of Response.body to download and cache the audio file in chunks. If the download is interrupted, continue downloading from the breakpoint next time.
[0060] In Service Worker, cache audio resources are cached through caches.open() and cache.put() methods. When an audio request is issued, it is first searched from the cache. If it is not found, it is obtained from the network and added to the cache at the same time.
[0061] Use IndexedDB to store metadata of audio files and the audio files themselves. For scenarios where a large number of audio files need to be persistently stored, use the File System Access API to directly operate the file system of the user's device.
[0062] In a second aspect, an embodiment of the present invention provides a music player setting device based on an H5 terminal, including:
[0063] Transfer module, transfer the audio processing logic with high performance requirements from JavaScript to WebAssembly module, write and compile Wasm code, integrate Wasm module in HTML5 player, and call the interface of Wasm module through JavaScript to perform audio processing;
[0064] Create a module and use Web Workers to create independent working threads to handle complex audio processing tasks. The main thread is responsible for UI rendering and user interaction, and the audio processing tasks are executed in the background thread.
[0065] Adaptation module: write a unified audio API adaptation layer, encapsulate the differences in the implementation of audio APIs by different browsers, provide a consistent interface for the player to call, and test and adjust the adaptation layer code;
[0066] Integration module: integrates support for multiple audio formats in the player to ensure that audio files can be played in different browser environments. It also implements automatic format conversion function, which automatically converts audio files to the format supported by the current browser when uploading or playing them.
[0067] The cache module uses Service Workers to implement caching and offline playback of audio files, designs block caching and breakpoint resume mechanisms, supports caching and downloading of large files, and improves the stability of offline playback;
[0068] The storage module uses IndexedDB and File System Access API browser local storage technology to store and manage audio files and realize the reading and management of audio files.
[0069] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:
[0070] at least one processor; and,
[0071] a memory communicatively connected to the at least one processor; wherein,
[0072] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the music player setting method based on the H5 end in any of the aforementioned first aspects or any of the implementations of the first aspect.
[0073] In a fourth aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the H5-based music player setting method in the aforementioned first aspect or any implementation of the first aspect.
[0074] In the fifth aspect, an embodiment of the present invention further provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the music player setting method based on the H5 end in the aforementioned first aspect or any implementation of the first aspect.
[0075] The H5-based music player setting scheme in the embodiment of the present invention includes: transferring the audio processing logic with high performance requirements from JavaScript to the WebAssembly module, writing and compiling Wasm code, integrating the Wasm module in the HTML5 player, and calling the interface of the Wasm module through JavaScript to perform audio processing; using Web Workers to create an independent work thread to handle complex audio processing tasks, the main thread is responsible for UI rendering and user interaction, and the audio processing task is executed in the background thread; writing a unified audio API adaptation layer, encapsulating the differences in the implementation of the audio API by different browsers, providing a consistent interface for the player to call, and testing and adjusting the adaptation layer code; integrating support for multiple audio formats in the player to ensure that audio files can be played in different browser environments, realizing the automatic format conversion function, and automatically converting the audio file to the format supported by the current browser when uploading or playing the audio file; using Service Workers to realize the caching and offline playback of audio files, designing block caching and breakpoint resume transmission mechanisms, supporting the caching and downloading of large files, and improving the stability of offline playback; using IndexedDB and File System Access API browser local storage technology to store and manage audio files, and realizing the reading and management of audio files. The present invention optimizes performance by introducing WebAssembly and multithreading technology, develops a cross-browser audio API adaptation layer and an automatic format conversion mechanism to enhance compatibility, uses enhanced ServiceWorkers and local storage technology to achieve reliable offline support, integrates DRM technology and dynamic watermarks to protect copyright, uses intelligent resource management algorithms and hardware acceleration technology to control resource consumption, and expands functions to achieve background playback support, integrate advanced audio effects, and rich user interaction and customization functions. This solution solves the shortcomings of existing H5-end music players in terms of performance, compatibility, offline support, copyright protection, resource consumption, and functionality, significantly improves overall performance and user experience, and provides users with smoother, more efficient, safer, and richer music playback services. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0077] Figure 1 A flowchart of a method for setting a music player based on an H5 terminal provided in an embodiment of the present invention;
[0078] Figure 2 A schematic diagram of another method for setting a music player based on an H5 terminal provided in an embodiment of the present invention;
[0079] Figure 3 A schematic diagram of the structure of a music player setting device based on an H5 terminal provided in an embodiment of the present invention;
[0080] Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0081] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0082] The following describes the embodiments of the present disclosure through specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.
[0083] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement the device and / or practice the method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.
[0084] It should also be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present disclosure. The drawings only show components related to the present disclosure rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0085] Additionally, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the aspects described may be practiced without these specific details.
[0086] The present disclosure embodiment provides a method for setting a music player based on an H5 terminal. The method for setting a music player based on an H5 terminal provided in this embodiment can be executed by a computing device, which can be implemented as software, or as a combination of software and hardware, and which can be integrated in a server, a terminal device, etc.
[0087] See also Figure 1 and Figure 2 The present disclosure provides a method for setting a music player based on an H5 terminal, including:
[0088] S101, transfer the audio processing logic with high performance requirements from JavaScript to the WebAssembly module, write and compile Wasm code, integrate the Wasm module in the HTML5 player, and call the Wasm module interface through JavaScript to perform audio processing.
[0089] To integrate the WebAssembly (Wasm) module in the HTML5 player to improve the performance of the audio processing logic, follow these steps:
[0090] S1011. Writing Wasm modules
[0091] Choose a language: First, you can choose a language that supports compilation to Wasm to write the audio processing logic, such as C, C++, or Rust, which can more directly control the underlying resources and thus optimize performance.
[0092] Implement audio processing logic: Implement audio processing algorithms such as audio filtering, volume adjustment, spectrum analysis, etc. in the selected programming language.
[0093] Export functions: Make sure functions you need to call from JavaScript are properly exported, for example by marking the function with the EMSCRIPTEN_KEEPALIVE macro in C / C++ or with the [no_mangle] pub extern "C" attribute in Rust.
[0094] S1012. Compile to WebAssembly
[0095] Install compilation tools: For C / C++, you need the Emscripten toolchain; for Rust, use rustup to install the wasm32unknownunknown target.
[0096] Compile process: Use the corresponding compilation command to compile the source code into a Wasm file. For example, in Emscripten, you may use a command like emcc your_audio_processor.cs WASM=1 o your_audio_processor.wasm.
[0097] S1013. Integrate Wasm module in HTML page
[0098] Loading Wasm modules: Use JavaScript's WebAssembly API to asynchronously load compiled Wasm files. You can use the WebAssembly.instantiateStreaming method or download the .wasm file first and then use WebAssembly.instantiate.
[0099] S1014. Calling the Wasm module interface
[0100] Interaction design: Define the interface functions of the Wasm module and ensure that they accept and return JavaScript-compatible data types (such as ArrayBuffer or TypedArrays).
[0101] Data transfer: Audio data is often handled as floating point arrays, which may require conversion between JavaScript and Wasm. Using Float32Array to interact with Wasm memory is a common practice.
[0102] Call processing function: Access and call the previously exported audio processing function through the Wasm instance, passing a reference or pointer to the audio data.
[0103] S1015. Integration into HTML5 player
[0104] Listening for play events: <audio>In a player tag or built using the Web Audio API, listen for playback progress or data stream events.
[0105] Process audio in real time: When audio data is available, the processing function in the Wasm module is called to process the data, and then the processed data is sent back to the player to continue the playback process.
[0106] S102, using Web Workers to create an independent working thread to handle complex audio processing tasks, the main thread is responsible for UI rendering and user interaction, and the audio processing task is executed in the background thread.
[0107] Specifically, you can create a new JavaScript file (for example, audioProcessor.js), which will serve as the Web Worker script and contain the logic of audio processing.
[0108] In audioProcessor.js, write audio processing functions. This may include complex operations such as decoding, filtering, and applying special effects to audio data. Web Workers run in an isolated environment. Web Workers cannot access the DOM or use certain properties of the window object.
[0109] In the main HTML file or related JavaScript file, initialize a new Web Worker instance and specify the previously created audioProcessor.js as the entry script of the worker thread.
[0110] When you need to process audio data, you can send the data to the Worker thread through the postMessage method. In the Worker script, listen to the message event to receive the instructions of the main thread. After processing, return the result to the main thread through postMessage. In the main thread, listen to the message event of the Worker to receive and process the results of audio processing.
[0111] Through such an architecture, time-consuming audio processing tasks can be effectively assigned to background threads, thus avoiding blocking the main thread and ensuring the smoothness and responsiveness of the user interface.
[0112] S103, write a unified audio API adaptation layer, encapsulate the differences in the implementation of the audio API by different browsers, provide a consistent interface for the player to call, and test and adjust the adaptation layer code.
[0113] Writing a unified audio API adaptation layer can eliminate the differences in audio processing APIs between different browsers and ensure that the player can work stably across browsers. This can be achieved through the following steps:
[0114] First, study the Web Audio API, HTML5 in detail <audio>Tags and implementation details and differences specific to each browser. Determine what basic features the player needs, such as audio loading, playing, pausing, volume control, time skipping, audio decoding, etc.
[0115] Design a set of API interfaces that cover all necessary audio operations. For example:
[0116] - loadAudio(url): loads an audio file.
[0117] - play(): Start playing audio.
[0118] - pause(): Pauses playback.
[0119] - stop(): Stops playback and resets to the beginning.
[0120] - setVolume(volume): sets the volume.
[0121] - seek(time): jump to the specified playback time.
[0122] For each function, write adaptation code so that the same interface can be called in Chrome, Firefox, Safari, Edge and other browsers to achieve the expected behavior. Use feature detection to determine which audio API the current browser supports and choose the implementation path accordingly. For functions that are not widely supported, polyfill can be used to simulate the implementation.
[0123] Through the above steps, a robust and cross-browser compatible audio API adaptation layer can be built to provide stable and unified audio processing capabilities for HTML5 players.
[0124] S104, integrating support for multiple audio formats in the player to ensure that audio files can be played in different browser environments, and realizing automatic format conversion function, automatically converting audio files to the format supported by the current browser when uploading or playing audio files.
[0125] You can determine the audio formats that need to be supported. Common audio formats include MP3, WAV, AAC, Ogg Vorbis, etc. Consider browser compatibility. For example, MP3 has good support in most browsers, but Ogg Vorbis may not be supported in some browsers.
[0126] Use a JavaScript player library that supports multiple audio formats, such as Howler.js, SoundManager2, or Buzz.js. These libraries usually automatically detect the formats supported by the browser and try to play the provided audio file. Furthermore, you can provide audio files in multiple formats and let the player library automatically select the best format.
[0127] When a user uploads an audio file, the backend server can detect the format of the file. If the uploaded audio format is not supported by all browsers, the server can use an audio conversion library (such as FFmpeg, LAME MP3 encoder, SoX, etc.) to convert the audio file to a more compatible format. The converted audio file can be stored as multiple versions to support different browsers and devices.
[0128] On the front end, you can use JavaScript to detect the audio formats supported by the browser. This can be done by checking <audio>element's canPlayType() method. Based on the detected support, the front end can request the appropriate audio file version.
[0129] If an audio file cannot be played in a specific browser, the front end should be able to handle the situation. For example, it can display an error message and provide a download link or an alternative audio file.
[0130] As a way, you can use the JavaScript canPlayType() method to detect the browser's support for a specific audio format. If it is not supported, you can consider using the Web Audio API or a third-party library (such as ffmpeg.js) to convert the audio format on the client side. This usually involves sending the audio file to the server for conversion and then returning a link in a format suitable for the current browser.
[0131] S105, use Service Workers to implement caching and offline playback of audio files, design block caching and breakpoint resumption mechanisms, support caching and downloading of large files, and improve the stability of offline playback.
[0132] To use Service Workers to achieve efficient caching and offline playback of audio files, and to design a block cache and breakpoint resume mechanism to support large file processing, you can include the following steps:
[0133] Register the Service Worker script in the main page, and in the Service Worker's `install` event handler, use the Cache API to pre-cache the audio file or its manifest file. For large files, consider caching only part of the file information (such as metadata) to reduce the burden of initial installation.
[0134] By listening to the `fetch` event, Service Worker can intercept all network requests, including requests for audio files. Try to return the audio file from the cache. If the cache is not available, get it from the network and add it to the cache after successful retrieval. This allows offline playback even when the network is unstable or disconnected.
[0135] You can split large audio files into multiple small chunks, each of which is cached independently. Set the server to support the Range request header so that the client can request specific parts of the file. When the user starts playing a piece of audio, Service Worker dynamically caches the chunks of the audio, giving priority to the part that is about to be played, to reduce initial loading time and storage space requirements.
[0136] Maintain a download status on the client and server to record the downloaded chunk information. When the network is interrupted or the user stops downloading and restarts, the download can be resumed from the breakpoint. Use the HTTP Range header to request a specific range of data from the server to achieve breakpoint resuming.
[0137] It can also predictively cache audio content that may be played next based on the user's playback habits and current network conditions.
[0138] S106 uses IndexedDB and File System Access API browser local storage technology to store and manage audio files, and realizes the reading and management of audio files.
[0139] By combining IndexedDB and the File System Access API, audio files can be efficiently stored and managed on the browser side, improving user experience and application performance.
[0140] IndexedDB is a non-relational database built into the browser, suitable for storing large amounts of structured data, including binary large objects (such as audio files). It is very suitable for storing audio files downloaded by users, supporting query, indexing, and transaction processing.
[0141] The audio file is read as a Blob object, and then these Blobs are stored in the database through IndexedDB transactions. The stored audio Blob can be quickly found and read through the index, and then the URL generated by URL.createObjectURL(Blob) can be created to make the audio available in ` <audio>`Play in the tag. Use IndexedDB's indexing and querying capabilities to easily manage and organize the user's favorite audio files, such as by name, artist, and album.
[0142] The File System Access API allows web applications to directly access the user's local file system and perform file read and write operations. For audio file management, this API is particularly suitable for allowing users to choose to save or open audio files in a specific location. You can select a location to save audio files downloaded from the Internet. After the application obtains write permission through the File System Access API, it can directly write the audio Blob stored in IndexedDB to the location specified by the user. You can also select local audio files through this API. After reading, the application can choose to store them in IndexedDB or use them directly for playback, providing a more flexible file management method.
[0143] When a user downloads audio, they first obtain the audio Blob through a network request, store it in IndexedDB, and optionally save it to the local file system through the File System Access API.
[0144] Maintain user-created playlists in IndexedDB, each of which is associated with a series of audio references (IDs or indexes). Even without a network connection, the app can read audio blobs from IndexedDB and play them.
[0145] Leverage the File System Access API to provide a user interface to browse, delete, or add local audio files to the application's playlist.
[0146] This architecture not only improves the offline availability and responsiveness of the app, but also enhances the user's control over audio files, improving the overall experience.
[0147] The present invention proposes an improved H5 music player technical solution, which optimizes performance by introducing WebAssembly and multi-threading technology, develops a cross-browser audio API adaptation layer and an automatic format conversion mechanism to enhance compatibility, uses enhanced Service Workers and local storage technology to achieve reliable offline support, integrates DRM technology and dynamic watermarks to protect copyright, uses intelligent resource management algorithms and hardware acceleration technology to control resource consumption, and expands functions to achieve background playback support, integrate advanced audio effects, and rich user interaction and customization functions. This solution aims to solve the shortcomings of existing H5 music players in terms of performance, compatibility, offline support, copyright protection, resource consumption, and functionality, significantly improve overall performance and user experience, and provide users with smoother, more efficient, safer, and richer music playback services.
[0148] According to a specific implementation of the embodiment of the present disclosure, the method further includes:
[0149] Encrypt and protect audio content during playback, configure and deploy DRM servers, manage encryption keys and licenses, and ensure secure transmission and playback of audio content;
[0150] Embed dynamic watermarks in audio streams, design and implement dynamic watermark embedding and detection algorithms to ensure that the sound quality is not affected.
[0151] According to a specific implementation of the embodiment of the present disclosure, the method further includes:
[0152] Develop intelligent resource management algorithms to dynamically adjust the player's resource usage based on current system resources and audio playback conditions, optimize algorithm performance, and reduce unnecessary resource consumption;
[0153] Take advantage of the hardware acceleration capabilities of modern browsers to improve audio processing and rendering performance, adjust and optimize the audio processing flow, and reduce CPU load.
[0154] According to a specific implementation of the embodiment of the present disclosure, the method further includes:
[0155] Use Page Visibility API and Background Fetch API to ensure smooth audio playback in the browser background, dealing with the limitations of browser background tasks;
[0156] Use the advanced audio effect processing functions provided by the Web Audio API to develop equalizer and reverberation sound effect functions, and provide a user-adjustable sound effect parameter interface;
[0157] It provides visual audio waveform, synchronized lyrics display, and playlist management functions, allowing users to adjust the player interface and function settings according to their personal preferences.
[0158] According to a specific implementation of the embodiment of the present disclosure, the audio processing logic with high performance requirements is transferred from JavaScript to the WebAssembly module, the Wasm code is written and compiled, the Wasm module is integrated in the HTML5 player, and the interface of the Wasm module is called by JavaScript to perform audio processing, including:
[0159] Select a programming language that compiles to Wasm, and implement audio filtering, volume adjustment, and spectrum analysis in the selected programming language;
[0160] Mark the function with EMSCRIPTEN_KEEPALIVE macro, export the function to be called from JavaScript, and compile the source code into a Wasm file using the command emcc your_audio_processor.cs WASM=1 o your_audio_processor.wasm;
[0161] Use WebAssembly.instantiateStreaming to asynchronously load compiled Wasm files from JavaScript’s WebAssembly API;
[0162] Define the interface function of the Wasm module, which accepts and returns JavaScript-compatible data types, accesses and calls the previously exported audio processing function through the Wasm instance, and passes a reference or pointer to the audio data;
[0163] In HTML5 <audio>In a tag or a player built using the Web Audio API, listen for playback progress or data stream events. When audio data is available, call the processing function in the Wasm module to process the data, and then send the processed data back to the player to continue the playback process.
[0164] According to a specific implementation of the embodiment of the present disclosure, the use of Web Workers to create an independent work thread to handle complex audio processing tasks, the main thread is responsible for UI rendering and user interaction, and the audio processing task is executed in the background thread, including:
[0165] Create a new JavaScript file audioProcessor.js. This file will be the Web Worker script containing the audio processing logic.
[0166] In audioProcessor.js, write audio processing functions, including decoding, filtering, and applying special effects to audio data;
[0167] In the main HTML file, initialize a new Web Worker instance and specify the previously created audioProcessor.js as the entry script of the worker thread;
[0168] When audio data needs to be processed, the data is sent to the Worker thread through the postMessage method. In the Worker script, the message event is listened to to receive the instructions of the main thread. After the processing is completed, the result is returned to the main thread through postMessage. In the main thread, the message event of the Worker is listened to to receive and process the result of the audio processing.
[0169] According to a specific implementation of the embodiment of the present disclosure, the unified audio API adaptation layer is written to encapsulate the differences in the implementation of the audio API by different browsers, provide a consistent interface for the player to call, and test and adjust the adaptation layer code, including:
[0170] After determining the operation functions included in the player, set the API interface corresponding to the operation functions;
[0171] For each operation function, write adaptation code so that the same interface can be called in multiple browsers to achieve the expected behavior;
[0172] Feature detection is used to determine which audio API the current browser supports, and the implementation path is selected accordingly. For unsupported features, polyfill is used to simulate the implementation.
[0173] According to a specific implementation of the embodiment of the present disclosure, the method further includes:
[0174] Use JavaScript's canPlayType() method to detect browser support for a specific audio format. If not, use the Web Audio API to convert the audio format on the client side.
[0175] Register the Service Worker script in the main page or application shell, and use the fetch event listener and the ReadableStream feature of Response.body to download and cache the audio file in chunks. If the download is interrupted, continue downloading from the breakpoint next time.
[0176] In Service Worker, cache audio resources are cached through caches.open() and cache.put() methods. When an audio request is issued, it is first searched from the cache. If it is not found, it is obtained from the network and added to the cache at the same time.
[0177] Use IndexedDB to store metadata of audio files and the audio files themselves. For scenarios where a large number of audio files need to be persistently stored, use the File System Access API to directly operate the file system of the user's device.
[0178] Corresponding to the above method embodiment, see Figure 3 The embodiment of the present invention further discloses a music player setting device 30 based on an H5 terminal, comprising:
[0179] The transfer module 301 transfers the audio processing logic with high performance requirements from JavaScript to the WebAssembly module, writes and compiles Wasm code, integrates the Wasm module in the HTML5 player, and calls the Wasm module interface through JavaScript to perform audio processing;
[0180] Creating module 302, using Web Workers to create independent working threads to handle complex audio processing tasks, the main thread is responsible for UI rendering and user interaction, and the audio processing tasks are executed in the background thread;
[0181] Adaptation module 303, writes a unified audio API adaptation layer, encapsulates the differences in the implementation of audio API by different browsers, provides a consistent interface for the player to call, and tests and adjusts the adaptation layer code;
[0182] Integration module 304 integrates support for multiple audio formats in the player to ensure that audio files can be played in different browser environments and realizes automatic format conversion function. When uploading or playing audio files, they are automatically converted to the format supported by the current browser;
[0183] Cache module 305, using Service Workers to implement caching and offline playback of audio files, designing block caching and breakpoint resume mechanisms, supporting caching and downloading of large files, and improving the stability of offline playback;
[0184] The storage module 306 uses IndexedDB and File System Access API browser local storage technology to store and manage audio files, thereby realizing the reading and management of audio files.
[0185] See also Figure 4 The embodiment of the present invention further provides an electronic device 60, the electronic device comprising:
[0186] at least one processor; and,
[0187] a memory communicatively connected to the at least one processor; wherein,
[0188] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the music player setting method based on the H5 end in the aforementioned method embodiment.
[0189] An embodiment of the present invention further provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the aforementioned method embodiment.
[0190] An embodiment of the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the music player setting method based on the H5 terminal in the aforementioned method embodiment.
[0191] Reference below Figure 4 , which shows a schematic diagram of the structure of an electronic device 60 suitable for implementing the embodiment of the present disclosure. The electronic device in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0192] like Figure 4 As shown, the electronic device 60 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 60 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0193] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 60 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 4 The electronic device 60 is shown with various devices, but it should be understood that it is not required to implement or have all the devices shown. More or fewer devices may be implemented or have instead.
[0194] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0195] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.< / audio> < / audio> < / audio> < / audio> < / audio> < / audio>
Claims
1. A music player setting method based on H5 terminal, characterized in that: include: Transfer high-performance audio processing logic from JavaScript to WebAssembly module, write and compile Wasm code, integrate Wasm module in HTML5 player, and call Wasm module interface through JavaScript to process audio. Use Web Workers to create independent worker threads to handle complex audio processing tasks. The main thread is responsible for UI rendering and user interaction, and audio processing tasks are executed in the background thread. Write a unified audio API adaptation layer to encapsulate the differences in the implementation of audio APIs by different browsers, provide a consistent interface for players to call, and test and adjust the adaptation layer code; Integrate support for multiple audio formats in the player to ensure that audio files can be played in different browser environments, and implement automatic format conversion. When uploading or playing audio files, they are automatically converted to the format supported by the current browser; Use Service Workers to implement caching and offline playback of audio files, design block caching and breakpoint resume mechanisms, support caching and downloading of large files, and improve the stability of offline playback; Use IndexedDB and File System Access API browser local storage technology to store and manage audio files, and realize the reading and management of audio files.
2. The method according to claim 1, characterized in that The method further comprises: Encrypt and protect audio content during playback, configure and deploy DRM servers, manage encryption keys and licenses, and ensure secure transmission and playback of audio content; Embed dynamic watermarks in audio streams, design and implement dynamic watermark embedding and detection algorithms to ensure that the sound quality is not affected.
3. The method according to claim 2, characterized in that The method further comprises: Develop intelligent resource management algorithms to dynamically adjust the player's resource usage based on current system resources and audio playback conditions, optimize algorithm performance, and reduce unnecessary resource consumption; Take advantage of the hardware acceleration capabilities of modern browsers to improve audio processing and rendering performance, adjust and optimize the audio processing flow, and reduce CPU load.
4. The method according to claim 3, characterized in that The method further comprises: Use Page Visibility API and Background Fetch API to ensure smooth audio playback in the browser background, dealing with the limitations of browser background tasks; Use the advanced audio effect processing functions provided by the Web Audio API to develop equalizer and reverberation sound effect functions, and provide a user-adjustable sound effect parameter interface; It provides visual audio waveform, synchronized lyrics display, and playlist management functions, allowing users to adjust the player interface and function settings according to their personal preferences.
5. The method according to claim 4, characterized in that The audio processing logic with high performance requirements is transferred from JavaScript to the WebAssembly module, the Wasm code is written and compiled, the Wasm module is integrated into the HTML5 player, and the interface of the Wasm module is called through JavaScript to perform audio processing, including: Select a programming language that compiles to Wasm, and implement audio filtering, volume adjustment, and spectrum analysis in the selected programming language; Mark the function with EMSCRIPTEN_KEEPALIVE macro, export the function to be called from JavaScript, and compile the source code into Wasm file using emccyour_audio_processor.cs WASM=1 o your_audio_processor.wasm command; Use WebAssembly.instantiateStreaming to asynchronously load compiled Wasm files from JavaScript’s WebAssembly API; Define the interface function of the Wasm module, which accepts and returns JavaScript-compatible data types, accesses and calls the previously exported audio processing function through the Wasm instance, and passes a reference or pointer to the audio data; In HTML5 <audio> In a tag or a player built using the Web Audio API, listen for playback progress or data stream events. When audio data is available, call the processing function in the Wasm module to process the data, and then send the processed data back to the player to continue the playback process.< / audio> 6. The method according to claim 5, characterized in that The method of using Web Workers to create an independent working thread to handle complex audio processing tasks is described. The main thread is responsible for UI rendering and user interaction, and the audio processing tasks are executed in the background thread, including: Create a new JavaScript file audioProcessor.js. This file will be the Web Worker script containing the audio processing logic. In audioProcessor.js, write audio processing functions, including decoding, filtering, and applying special effects to audio data; In the main HTML file, initialize a new Web Worker instance and specify the previously created audioProcessor.js as the entry script of the worker thread; When audio data needs to be processed, the data is sent to the Worker thread through the postMessage method. In the Worker script, the message event is listened to to receive the instructions of the main thread. After the processing is completed, the result is returned to the main thread through postMessage. In the main thread, the message event of the Worker is listened to to receive and process the result of the audio processing.
7. The method according to claim 6, characterized in that The unified audio API adaptation layer is written to encapsulate the differences in the implementation of the audio API by different browsers, provide a consistent interface for the player to call, and test and adjust the adaptation layer code, including: After determining the operation functions included in the player, set the API interface corresponding to the operation functions; For each operation function, write adaptation code so that the same interface can be called in multiple browsers to achieve the expected behavior; Feature detection is used to determine which audio API the current browser supports, and the implementation path is selected accordingly. For unsupported features, polyfill is used to simulate the implementation.
8. The method according to claim 7, characterized in that The method further comprises: Use JavaScript's canPlayType() method to detect browser support for a specific audio format. If not, use the Web Audio API to convert the audio format on the client side. Register the Service Worker script in the main page or application shell, and use the fetch event listener and the ReadableStream feature of Response.body to download and cache the audio file in chunks. If the download is interrupted, continue downloading from the breakpoint next time. In Service Worker, cache audio resources are cached through caches.open() and cache.put() methods. When an audio request is issued, it is first searched from the cache. If it is not found, it is obtained from the network and added to the cache at the same time. Use IndexedDB to store metadata of audio files and the audio files themselves. For scenarios where a large number of audio files need to be persistently stored, use the File System Access API to directly operate the file system of the user's device.
9. A music player setting device based on H5 terminal, characterized in that: include: Transfer module, transfer the audio processing logic with high performance requirements from JavaScript to WebAssembly module, write and compile Wasm code, integrate Wasm module in HTML5 player, and call the interface of Wasm module through JavaScript to perform audio processing; Create a module and use Web Workers to create independent working threads to handle complex audio processing tasks. The main thread is responsible for UI rendering and user interaction, and the audio processing tasks are executed in the background thread. Adaptation module: write a unified audio API adaptation layer, encapsulate the differences in the implementation of audio APIs by different browsers, provide a consistent interface for the player to call, and test and adjust the adaptation layer code; Integration module: integrates support for multiple audio formats in the player to ensure that audio files can be played in different browser environments. It also implements automatic format conversion function, which automatically converts audio files to the format supported by the current browser when uploading or playing them. The cache module uses Service Workers to implement caching and offline playback of audio files, designs block caching and breakpoint resume mechanisms, supports caching and downloading of large files, and improves the stability of offline playback; The storage module uses IndexedDB and File System Access API browser local storage technology to store and manage audio files and realize the reading and management of audio files.
10. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the H5-based music player setting method described in any one of claims 1-8.
