Saturday, 7 May 2011

Salesforce: Play Attachments on the same page

I came back again with a very interesting thing this time.
These day I worked a lot with the attachments and realized that if we have any audio/video attachments in org then to see them first we need to download it on local machine and only then we can play with it.

I wanted to build a script which can  play attachment in the salesforce itself without asking for download.

Now the question is how this is useful :
I had a voice call with the customer and attached this call with the customer record. Now after some days I want to confirm a point was discussed in the call. So what I need to do :

  • Go to the customer record.
  • Click on the attachment.
  • Download the attachment.
  • Save on local disk.
  • Play audio.
  • Delete file once audio done to escape from the unnecessary storage on machine.

So here you can see that, there will be 6 step to listen a audio file, while we just wanted to hear the discussion again. These step will be always be repeated whenever we want to listen this conversation.

So if there could be a utility which could play the files in org itself without asking for downloading, that would be better. That's whay I started work on this idea and now here I am.
I have created a visualforce page and embedded this with some JS files, which allow to play the audio files on the same screen. This shows a player only with the audio file in the same row. Check it here:

This page can be added as inline Visualforce page with any object which supports attachments.Like :

I have created a Un-managed package for this. So you can modify this as per your requirement.
Here is the URL:

Please comment if any modification can be done to make it better.



  1. Thanks for this Bhawani. A really nice post. Now I can get rid of the process of first downloading the attachment and then listening to it.

  2. Great Post Bhawani. I am trying to do something similar. My audio files are not stored as attachments, but are retrieved through an APEX CallOut to a .NET web service. The web service sends the audio blob as a base64binary (its a byte array that gets serialized like this). The helper controller class retrieves this string and displays in VF page byte-for-byte correct. The problem comes when I try to play this content by using a mime type of audio/wav in the VF page. At that time the player does not decode the blob properly. I have tried doing a base 64 decode to convert the string to a blob before rendering, but it does not help.

    Any ideas on how I can handle this?


    1. did you get any input on this..Please help me.i need to do the same in Video

  3. nice post. but do you have a static resource for media/movie player?

  4. This comment has been removed by the author.

  5. @Eugene: Yes, player is stored as static resource.

  6. thanks bhavi. i mean, what you used here is a audio player, it can only play sound files. what if i want to play a video? do you have a file other than a audio player that will allow me to play video attachments?it would really help alot. thank you

  7. i'm trying to find a swf player similar to your player.swf. but i want it to also play videos. thanks in advance

  8. Hello Bhavi:

    Is it possible that you can share the visualforce page of how to add the static resource you have? I tried to click on the first link and got the error of asking me to login. Thanks.

  9. Hi,
    I have install this app in my org. It's really a nice app.
    But this app is not supported all audio formats,it's work only for .mp3 format.

  10. This comment has been removed by the author.

  11. This comment has been removed by the author.

  12. I've tried posting my contribution to the blog, the video player. No success, so, email me if you want it.


    ps. its complementary to this great install.

  13. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!

    Salesforce Administrator Training in Chennai

  14. I have installed the package and what I am doing is i attached a file under notes and attachements related list (mp3). I still dont have the inline play button

    1. You should change the url of the document in the visualforce page , replace this Url ("") with your current org url.

  15. I like this example. How would I modify it to play audio from a custom object rather than the lead object? Can it play wav files, or just mp3?

  16. Thank you so much for this post. When I demo to people, they fall into ecstasy, and say things like, "I didn't even know you could do something like this." And then they ask for more volume. Is there a way to pass a volume parameter into the player ?

    1. Hi Eric, Definitely there should a one. I need to dig into this again as I wrote this blog years ago.

    2. You can reach me on "" directly.

  17. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
    Salesforce training in Chennai

  18. Hi Bhavi thanks for sharing this.
    But it is not supported in mozilla firefox can u send me any suggestions for dis.

  19. This app can't be installed.
    There are problems that prevent this package from being installed.
    Method does not exist or incorrect signature: Test.startTest() PlayAudio: Method does not exist or incorrect signature: Test.startTest()
    Apex class 'PlayAudio' does not exist PlayMP3: Apex class 'PlayAudio' does not exist

  20. What value do you really bring that benefits your market in ways that your competitors wouldn’t dream of proposing?
    <a href=">salesforce services in Dallas</a>

  21. i am getting below error help me

    Method does not exist or incorrect signature: void startTest() from the type TEST PlayAudio: Method does not exist or incorrect signature: void startTest() from the type TEST
    Method does not exist or incorrect signature: void stopTest() from the type TEST PlayAudio: Method does not exist or incorrect signature: void stopTest() from the type TEST
    Apex class 'PlayAudio' does not exist

  22. I am getting this error:

    Invalid conversion from runtime type Case to Lead
    An unexpected error has occurred. Your development organization has been notified.

  23. Still having probleMs getting the inline player to show I've corrected the URL

  24. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    Learn more about:
    salesforce communities solutions
    salesforce to salesforce migration
    global rollout consulting services
    salesforce service cloud solution