简体   繁体   English

使用PRIMEFACES,点击按钮即可播放mp3?

[英]Play mp3 with button click with PRIMEFACES?

i want to play a media mp3 by clicking a button with primefaces, it is possible? 我想通过单击带有撇号的按钮来播放媒体mp3,这可能吗? i try to update the media tag but doesn't work, when the page load the sound plays great, but i want to sound again after click event 我尝试更新媒体标签,但不起作用,当页面加载时声音播放很好,但是我想在单击事件后再次发出声音

    <h:form>
        <p:commandButton value="play" update="media"/>

        <p:media id="media" value="/resources/sounds/ding.mp3" player="quicktime" style="visibility: hidden;">
                <f:param name="autoPlay" value="true" />
        </p:media>
   </h:form>

The only apparent way is with javascript. 唯一明显的方法是使用javascript。

  1. Enable javascript control on the quicktime plugin (for older browser support) 在quicktime插件上启用javascript控制(以支持较早的浏览器)

     <p:media id="media" value="/resources/sounds/ding.mp3" player="quicktime" style="visibility: hidden;"> <f:param name="autoPlay" value="true" /> <f:param name="enablejavascript" value="true"/> </p:media> 
  2. call the Play method on the quicktime player in the onclick of the button 在按钮的onclick上调用quicktime播放器上的Play方法

     <p:commandButton onclick="document.media.Play();" value="play" update="media"/> 

This, to me, is not an ideal solution. 对我来说,这不是理想的解决方案。 If you were open to it, I'd recommend taking advantage of the new <audio/> tag available in HTML5 (and JSF 2.2) 如果您愿意的话,我建议您利用HTML5(和JSF 2.2)中提供的新<audio/>标签。

When you use ap:media, there's no associated generated id for this component. 当您使用ap:media时,此组件没有关联的生成ID。 What you want to do is to wrap your p:media on a container, such as an h:panelGrid. 您要做的是将p:media包装在一个容器上,例如h:panelGrid。 You get the following: 您得到以下信息:

<h:form>
  <p:commandButton value="play" update="mediaPanel"/>
  <h:panelGrid id="mediaPanel">
    <p:media id="media" value="/resources/sounds/ding.mp3" player="quicktime"
          style="visibility: hidden;">
      <f:param name="autoPlay" value="true" />
    </p:media>
  </h:panelGrid>
<h:form>

I tested this using PF5.0 and it works. 我使用PF5.0进行了测试,并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM