Vaadin sound file not working when I use it to play .m4a sound files (Vaadin 7.3.2)
I am using this to display html5 audio in one of my Vaadin apps. When I just query the data in the browser and save the file, it can be played, but it always fails when I try to use it in Vaadin.
Can you point out what I am 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();
}
}
+3
source to share
1 answer
Are you sure your browser supports the format? If you try it with simple html, can you reproduce it?
If the browser supports the format, I suggest the following:
Audio audio = new Audio("MyAudio");
audio.setSource(new ThemeResource("audio/myAudio.m4a"));
myLayout.addComponent(audio);
And you can put the file under your themes folder (or you can use it instead FileResource
).
EDIT
Perhaps 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";
}
};
0
source to share