Jump to content

Problem with Upload field in databases


yameth

Recommended Posts

Posted

A database I've made in Pages aims to make an audio - video gallery. Records added can be a Youtube or Soundcloud link or a direct upload.

When an mp3 is uploaded the default Embedded Player does not show but only a link for download.

I bought (NE) HTML5 Audio/Video Player hoping to address the audio player issue but the helpful author said that "the plugin as it is designed to work on editor content, whereas in this case the field that contained the attachment was an 'upload' type".

He also said that "the Pages app provides the ability to already present a player if desired" by adding the following code.

After setting the 'Display View Format' to Custom I added 

<audio controls><source src="{$value}"></audio>

So now the audio player shows BUT even if there is no uploaded record and under or above the Youtube video or Soundcloud player when one is linked. Please see attached. Under the Soundcloud link there is an audio player with nothing to play.

If I remove the code, still the dead upload link shows, which means there is something wrong when an upload field is added and cannot be used in conjunction with another field?

What do you think? Could be a bug?

Sorry if it looks a little confusing but thanks for looking anyway.

 

audioplayer.jpg

Posted
10 minutes ago, yameth said:

So now the audio player shows BUT even if there is no uploaded record  …

You need to load the code only if there was something uploaded to the field. This can be done by wrapping the code with:

{{if $formValue}}
// Your stuff
{{endif}}

 

Posted

Yup, that's the basics but it needs a little finesse to allow for peculiarities of an upload field if nothing has been uploaded (it actually does have content, and that is the url path to the uploads folder)

You also mentioned in your PM that your field is restricted to only allow certain audio attachments. So test for the extension of the allowed files appearing in the url ($value)

{{$audio = array("mp3","wma","wav");}}
{{if strlen(str_replace($audio, '', $value)) !== strlen($value)}}
<audio controls><source src="{$value}"></audio>
{{endif}}

Could even be extended out if the field also allowed video files to be uploaded

{{$audio = array("mp3","wma","wav");}}
{{$video = array("mp4");}}
{{if strlen(str_replace($audio, '', $value)) !== strlen($value)}}
<audio controls><source src="{$value}"></audio>
{{elseif strlen(str_replace($video, '', $value)) !== strlen($value)}}
<video controls><source src="{$value}"></video>
{{endif}}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...