Audio display by HTML5

  • Last update:  2021-04-15
  • I.Problem description

    When designing a report, how to add sound playback, background music, or realize sound warning to the report?

    II.Solution

    Use HTML5 <audio> tag

    Currently, the audio element supports three audio formats:

        IE9 Firefox3.5  Opera10.5 Chrome3.0    Safari3.0
      Ogg Vorbis
      √  √  √
      Mp3  √

      √  √
      Wav
      √  √
      √

    The attributes of the <audio> tag

    Attributes  Value  Description
      autoplay   autoplay  If this attribute is present, the audio will play as soon as it is ready
      controls   controls  If this property is present, the user will be shown controls, such as a play button
      loop   loop  If this attribute is present, the playback will restart whenever the audio ends
      preload   preload  If this attribute is present, the audio is loaded when the page loads and is ready to play

      If "autoplay" is used, the attribute is ignored

      src   src  URL of the audio to be played

    III.Resolution steps

    1) Add the following code in cell A1

    1.png

    <audio src="http://www.w3school.com.cn/i/song.ogg" controls="controls"  loop="loop"> Your browser does not support the audio element. </audio>

    2) Use HTML to display content in cell attributes

    2.png

    3) Save and preview, the effect is as follows (the display effect of different browsers is different)

    3.png

    4) If you want to do warnings and other operations, first add the id attribute to the <audio> tag, such as: add id="music1" to the code of cell A1

    <audio src="http://www.w3school.com.cn/i/song.ogg" controls="controls"  loop="loop" id="music1"> Your browser does not support the audio element. </audio>

    5) Click Template>Web Attributes>Pagination Preview(select the setting mode according to your own preview mode), choose Individually set for the template, and then add the Load end event, as shown in the figure below.

    (In actual use, you can set the playback after judging a certain value to achieve the warning effect)

    4.png

    var ms=document.getElementById('music1'); 
    ms.play();  
    //ms.pause();  

    6) Save and preview, it will play automatically.

    IV.Mobile effect

    Does not support this effect.

    Attachment List


    Theme: Report Application
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy