How to play MP3 files?

Introduction to the TWatch builder portal
Post Reply
mchavez
Site Admin
Posts: 31
Joined: Tue Nov 10, 2020 12:12 am

How to play MP3 files?

Post by mchavez »

The TWatch2020 can also play music. If you want to play a MP3 this is what you need to do.
  • First, you need to enable the "Audio" switch in "Settings" tab of the web portal
  • Create a new app
  • Upload the MP3 file as asset in the "Assets" tab (maximum file size: 3 MB)
  • Include the "audio.h" file at "Code" tab

    Code: Select all

    #include "audio.h"
    
  • Declare a global variable "AudioPlayer"

    Code: Select all

    AudioPlayer* __player;
    
  • Implement the __show method as follows

    Code: Select all

    void __show() {
      __player = new AudioPlayer("/my_mp3.mp3");
      __player->play();
    }
    
  • Implement the __hide method as follows

    Code: Select all

    void __hide() {
      __player->stop();
      delete(__player);
    }
    
  • Implement the __loop method as follows

    Code: Select all

    void __loop() {
      __player->loop();
    }
    
Finally, install the app in your watch and you can hear your beautifull music

The TWatchBuilder Team
Post Reply