1. Outline
The Unifinity application can play audio.
This article explains how to play audio files obtained via the Internet and resource-registered audio. Please take a look at the following cases that we can help you with.
- I want to play audio files downloaded from the Internet.
- I want to play an audio file defined in a resource.
The sample project used in the explanation can be downloaded from the following link. We hope you will take advantage of it.
2. Implementation method (explanation of key points only)
2-1. Screen Creation
Create a new screen as follows and place the buttons in it.
(1) Button
2-2. Creating download logic
Create and register logic to be used for downloading.
The logic used for the download is as follows
#1 Logic to download files from the network.
HTTP communication is performed to the URI of the audio file to download the file.
The downloaded file will be saved in the application area as "download.mp3".
#2 Play audio files. Name the playback process "Download" and specify "download.mp3" obtained in #1 above as the file name.
Please register the created logic in the "Download" button.
2-3. Creating Resource Call Logic
Create the logic to invoke the resource voice and set it to a button. The voice must be registered with the resource in advance.
Resource voice is registered by setting "keyword" from "Properties" > "Resources". keyword is used to invoke a resource.
The logic used for resource loading is as follows
#1 Call audio from a resource. Name the playback process "resource" and specify the keyword you just set in the "resource KEY" parameter.
Register the logic you have created in the "Resources" button.
2-4. Creation of Playback Stop Logic
Since the audio being played does not end until the end of the file is reached or until the playback is stopped by the "device/sound stop" logic, logic to stop playback is implemented from a separate button.
The logic used to stop playback is as follows
#1Stops the sound currently playing. Specify "Download" set as the name of the #2 "Device/Sound Playback" logic in #2-2.
#2Stops the sound currently playing. Specify the "resource" you set as the name of the #1 "Device/Sound Playback" logic in 2-3.
The created logic should be registered in the "Stop Voice" button.
This completes the setup for audio playback.
Run the application from the "Run" button on the menu icon to see if it works correctly.
Press each button and if the audio plays, you have succeeded.