code help
Permalink
Hi
I'm wanting to add to a single page some code that will pull the file link from an audio file attached to the page (handle 'audio'), and then for that link to be playable through say an html code such as:
There is an audio file attached to the pages attribute, and the player is displayed on the page, but it is for ever loading. I've tried this using the PHP Add-on Block and an error gets displayed which says:
An unexpected error occurred.
Call to a member function getAttribute() on null
I'm running on 5.8.1. Thanks for any pearls of wisdom.
Justyn
I'm wanting to add to a single page some code that will pull the file link from an audio file attached to the page (handle 'audio'), and then for that link to be playable through say an html code such as:
<?php $DownloadURL = $c->getAttribute('audio'); ?> <audio controls> <source src="<a href="<?php echo $DownloadURL; ?>"></a>" type="audio/mpeg"> Your browser does not support the audio element. </audio>
There is an audio file attached to the pages attribute, and the player is displayed on the page, but it is for ever loading. I've tried this using the PHP Add-on Block and an error gets displayed which says:
An unexpected error occurred.
Call to a member function getAttribute() on null
I'm running on 5.8.1. Thanks for any pearls of wisdom.
Justyn
Thanks. So code now is
Error message is now:
An unexpected error occurred.
Object of class Concrete\Core\Entity\File\File could not be converted to string
<?php $c = Page::getCurrentPage(); $DownloadURL = $c->getAttribute('audio'); ?> <audio controls> <source src="<a href="<?php echo $DownloadURL; ?>"></a>" type="audio/mpeg"> Your browser does not support the audio element. </audio>
Error message is now:
An unexpected error occurred.
Object of class Concrete\Core\Entity\File\File could not be converted to string
Try this
<?php $c = Page::getCurrentPage(); $file = $c->getAttribute('audio'); ?> <audio controls> <source src="<?php echo $file->getURL(); ?>" type="audio/mpeg"> Your browser does not support the audio element. </audio>
Very helpful thanks. It is a huge step forward. The player displays and there is no error message. Unfortunately it appears to be constantly trying to load the file so doesn't play. Any helpful thoughts?
Can you send a link to the page? There is no way to tell what might be wrong from just seeing this code.
The test site ishttp://churchinthepeak.org/test2/portfolio/project-1...
You need to remove the a tag from the src, if you look at my example it's been removed.
That's spot on. Sorry I thought I had copied and pasted the whole code, but obviously not. It works perfectly. Thank you SO much.
As for the code you have I believe what you need is this