本文介绍了Vaadin音频元素在播放.m4a声音文件时不起作用(Vaadin 7.3.2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我用它来在我的Vaadin应用程序之一中显示html5音频.当我只是在浏览器中请求数据并保存文件时,就可以播放该文件-但是当我在Vaadin中尝试播放该文件时,总是失败.

I use this to display html5 audio in one of my Vaadin application. When I simply requst the data in browser, and save the file, it can be played - but it always fails to do so, when I try it in Vaadin.

您能指出我在做什么错吗?

Can you point out, what am I doing wrong?

public class AudioArea extends Audio {

    public AudioArea(final int soundId) {
        super();
        StreamResource resource = new StreamResource(
            new StreamResource.StreamSource() {

                public InputStream getStream() {
                    byte[] data = MyVaadinUI.request.getBinaryData(
                            soundId, BinaryDataSource.TYPE_SOUND, 0, 0);
                    if (data == null) {
                        return null;
                    }
                    return new ByteArrayInputStream(data);
                }
            }, "");
        setSource(resource);
        markAsDirty();
    }
}

推荐答案

您确定您的浏览器支持该格式吗?如果您尝试使用纯HTML格式,可以播放吗?
如果浏览器支持该格式,那么我建议这样做:

Are you sure that your browser supports the format? If you try it with plain html can you play it?
If the browser supports the format, then I suggest this:

Audio audio = new Audio("MyAudio");
audio.setSource(new ThemeResource("audio/myAudio.m4a"));
myLayout.addComponent(audio);

您可以将文件放在主题文件夹下(或者可以使用FileResource代替).

And you could put the file under your theme folder (or you can use FileResource instead).

编辑

也许是缺少的MIME类型是问题所在

Maybe the missing MIME Type is the problem:

StreamResource resource = new StreamResource(
    new StreamResource.StreamSource() {

        public InputStream getStream() {
            byte[] data = MyVaadinUI.request.getBinaryData(
                    soundId, BinaryDataSource.TYPE_SOUND, 0, 0);
            if (data == null) {
                return null;
            }
            return new ByteArrayInputStream(data);
        }
    }, "") {
        @Override
        public String getMIMEType() {
            return "audio/mp4";
        }
    };

这篇关于Vaadin音频元素在播放.m4a声音文件时不起作用(Vaadin 7.3.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:56