function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pinkipinki 

audio for a visualforce page

Hi, I have the requirement like this. Say I have a Visualforce page which has '<apex:page> This is a new page </apex:page>'. Then I want an audio player on that page which will play this exact statement "This is a new page." Is this possible to be done in Apex? Or through Javascript on Apex? If anyone has done this or know about how it can be implemented, please share the relevant steps and code. 
Peter_sfdcPeter_sfdc
There is no visualforce custom tag that wraps playing media, or the HTML5 media tag types. 

I would suggest vanilla HTML for doing this as per the documentation here: 

http://www.w3schools.com/html/html5_audio.asp

In your case, you'd just want the URL to point to a resolveable URL, whether hosted in: 
  • A static resource
  • Some kind of content in Salesforce (attachment, chatter feed, etc.)
  • An external URL from a CMS, CDN, or whatever
Given your requirement of playing a single audio file I would use a zip static resource with several different files in it, so you can support as many browsers as possible. You'd then end up with something like this: 
<audio controls>
  <source src="{!URLFOR($Resource.AudioFiles, 'NewPage.ogg'}" type="audio/ogg">
  <source src="{!URLFOR($Resource.AudioFiles, 'NewPage.mp3'}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
If it were dynamic, I'd probably bind the src to a field that output some kind URL pointing to the file. My first choice would then use a formula field or some Apex to populate the value. If the dynamic value was not dependent on data in Salesforce, then I'd fall back to Javascript, most likely.  
pinkipinki
Hi Peter, thanks for your answer. But this text to be shown in the page comes from a field in an object in Salesforce and is not mp3 or audio file. It is dynamic and can change.I have looked into http://www.w3schools.com/html/html5_audio.asp but here the source element refers to specific audio files which is to be hosted as static resource in Salesforce. But here the text I need to be played is dynamic and also not an mp3 file. Please suggest how to do this.
MenteeMentee
Do you have any solution on this. I have a similiar requirement. I saved audio recordings in Files object. how can I play in visualforce page