Answers.Body: <p>I think the cleanest way to solve your issue is to create a new <code>Asset</code> for each of your audio files and relate it to your entries.</p>
  
  <pre><code>&lt;audio autoplay loop&gt;
      {% set audioFiles = entry.assetFieldHandle.all() %}
      {% for asset in audioFiles %}
          &lt;source src="{{ asset.getUrl() }}" type="{{ asset.getMimeType() }}"&gt;
      {% endif %}
  &lt;/audio&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-05-01T13:39:46.480Z
Answers.Text: Thanks for the answer, however I don't want the assets to have to be uploaded and need them contained to the plugin. It also doesn't really solve my issue of why the audio files won't play.
Answers.UserDisplayName: Owen Davey
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-05-01T13:40:46.173Z
Answers.Text: Are you using Craft 3 or Craft 2?
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-05-01T13:41:39.720Z
Answers.Text: Sorry, I should have mentioned that I'm using Craft 2. I'm stuck using this version due to my client.
Answers.UserDisplayName: Owen Davey
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-05-01T10:29:33.117Z
Answers.LastActivityDate: 2018-05-01T11:25:31.683Z
Answers.LastEditDate: 2018-05-01T11:25:31.683Z
Answers.UserDisplayName: Robin Schambach
Body: <p>Essentially I'm moving a static HTML site into Craft. I've created a new plugin for the site and have gotten a good chunk of it working however I'm having an issue where audio files won't play. </p>
  
  <p>The site is supposed to have music auto-playing and looping (it's a site for kids before you start judging me), and it works correctly on the static site, however nothing plays in my Craft instance and when I go to the direct URL for the audio file it won't play in browser either but doesn't give me a 404. If I "Save As" it does then download correctly.</p>
  
  <p>Code is very simple:</p>
  
  <pre><code>&lt;audio autoplay loop&gt;
          &lt;source src="{{ resourceUrl('somesite/audio/some_theme_full.ogg') }}" type="audio/ogg"&gt;
          &lt;source src="{{ resourceUrl('somesite/audio/some_theme_full.mp3') }}" type="audio/mpeg"&gt;
  &lt;/audio&gt;
  </code></pre>
  
  <p>The src generates correctly as e.g <a href="http://site.local/cpresources/somesite/audio/some_theme_full.mp3?d=1513706441" rel="nofollow noreferrer">http://site.local/cpresources/somesite/audio/some_theme_full.mp3?d=1513706441</a>.</p>
  
  <p>Any help would be wonderful!</p>
  
Tags: <templating><resources>
Title: Audio file won't play using resourceUrl inside plugin
ThreadText: # Audio file won't play using resourceUrl inside plugin
  
  (Asked by: username_0 on 2018-05-01)
  
  Essentially I'm moving a static HTML site into Craft. I've created a new plugin for the site and have gotten a good chunk of it working however I'm having an issue where audio files won't play.
  
  The site is supposed to have music auto-playing and looping (it's a site for kids before you start judging me), and it works correctly on the static site, however nothing plays in my Craft instance and when I go to the direct URL for the audio file it won't play in browser either but doesn't give me a 404. If I "Save As" it does then download correctly.
  
  Code is very simple:
  
  ```
  <audio autoplay loop>
          <source src="{{ resourceUrl('somesite/audio/some_theme_full.ogg') }}" type="audio/ogg">
          <source src="{{ resourceUrl('somesite/audio/some_theme_full.mp3') }}" type="audio/mpeg">
  </audio>
  
  ```
  
  The src generates correctly as e.g <http://site.local/cpresources/somesite/audio/some_theme_full.mp3?d=1513706441>.
  
  Any help would be wonderful!
  
  **Tags:** templating, resources
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-01. Score: 2
  
  I think the cleanest way to solve your issue is to create a new `Asset` for each of your audio files and relate it to your entries.
  
  ```
  <audio autoplay loop>
      {% set audioFiles = entry.assetFieldHandle.all() %}
      {% for asset in audioFiles %}
          <source src="{{ asset.getUrl() }}" type="{{ asset.getMimeType() }}">
      {% endif %}
  </audio>
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for the answer, however I don't want the assets to have to be uploaded and need them contained to the plugin. It also doesn't really solve my issue of why the audio files won't play.  
  > **username_1**: Are you using Craft 3 or Craft 2?  
  > **username_0**: Sorry, I should have mentioned that I'm using Craft 2. I'm stuck using this version due to my client.  
  
  ---
  
  