Forum Discussion
Embed audio in Power BI report from OneDrive or Sharepoint
- 7 years ago
Hi Omega
Change the "type" to your audio type.
<source src='******/**.your-type' type='audio/your type'>
Please know the limitation:
1.Audio and video files should meet the standard criteria for the HTML5 <audio> or <video> tag. There are some limitations in terms of file type (mp3, ogg), etc.
2.Audio and video content should be hosted online with a publicly accessible URL.
3.Sound or video will only work in Power BI Service. Controls will display in Power BI Desktop, but no content will load.
Best Regards
MaggieCommunity Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Owen,
Thank you for posting this.
I downloaded the file you attached to look at the two samples but only the Base64 seems to be working. Am I missing something?
Hi mnahmany
The issue with that example was that the MP3's web URL wasn't publicly accessible (as well as the link no longer being valid due to a change on my tenant).
So the Base64 string was valid but the web URL wasn't (unless you were logged in with an appropriate account).
Here is a version with a valid public URL from my Personal OneDrive as an example.
Regards
- OwenAuger1 year ago
Super User
Hi PatChan
Sure thing 🙂
1. MP3s where entire Base64 & HTML string can be stored as a text value in a table
The method I used in the original example only works if the entire HTML string including the Base64 encoded MP3 can be stored as a text value in a column. This means the entire string must be no more than 32,766 characters (see here).
Assuming this is the case, you can use this method.
The column I originally created contains text following the below this structure where <BASE64_ENCODED_MP3> is replaced with the Base64 encoding of the binary contents of an MP3 file:
<audio controls><source src='data:audio/mp3;base64,<BASE64_ENCODED_MP3>' type = 'audio/mp3'> </audio>If you have already loaded the binary content from source, here is a function that would create this HTML text is:
( MP3_Binary as binary) => let Base64 = Binary.ToText(MP3_Binary,BinaryEncoding.Base64), HTML = "<audio controls><source src='data:audio/mp3;base64,"& Base64 & "' type = 'audio/mp3'> </audio>" in HTML2. MP3s where the Base64 & HTML string is too large to be stored as a text value in a table
For longer MP3s, you will need to split the Base64-encoded MP3 data across multiple rows, similarly to how images were split in this post.
Again assuming that you have already loaded the binary content from source, you could use this function to create a table per MP3 containing the Base64 string split across rows:
(MP3_Binary as binary) => let SplitSize = 30000, Base64 = Binary.ToText(MP3_Binary,BinaryEncoding.Base64), Base64Split = Splitter.SplitTextByRepeatedLengths(SplitSize)(Base64), Positions = List.Positions(Base64Split), PartRecords = List.Transform(Positions, each [MP3 Part Index = _+1, MP3 Part Base64 = Base64Split{_}]), PartTable = Table.FromRecords(PartRecords, type table[MP3 Part Index = Int64.Type, MP3 Part Base64 = text]) in PartTableApplying this method, you end up with multiple rows per MP3, which must be reassembled by a measure.
In my sample PBIX attached, the measure I created is:
MP3 HTML = VAR MP3_Index = SELECTEDVALUE ( MP3[MP3 Index] ) VAR Result = IF ( NOT ISBLANK ( MP3_Index ), -- Require single selection VAR MP3_Name = SELECTEDVALUE ( MP3[MP3 Name] ) VAR Base64Concatenated = CONCATENATEX ( MP3, MP3[MP3 Part Base64], "", MP3[MP3 Part Index] ) VAR MP3HTML = "<label for='audio-player'>" & MP3_Name & "</label>" & "<audio id='audio-player' controls><source src='data:audio/mp3;base64," & Base64Concatenated & "' type = 'audio/mp3'> </audio>" RETURN MP3HTML ) RETURN ResultAs an example, I used the HTML visual to display the HTML per MP3:
Hope that helps!
Regards,
Owen
- PatChan1 year ago
Helper I
Thank you OwenAuger for responding so quickly! I managed to generate the binary64 string for my 4-sec recording using the python code below. It's surprising that a 4-sec recording can be translated to such a long string. Anyway, the recording got cut off sadly after 1-2 seconds. I am not sure why 😕 Please don't feel obliged to respond as I think this should be a separate thread already!