我在Google App Engine云存储中存储了mp3文件,我希望得到他们的持续时间。 我在这里的一个人的帮助下制作了这段代码,但不幸的是,AudioSystem类不能与Google App Engine云存储一起使用。 有人知道这样做的方法吗?
ListResult lr = gcsService.list(mybucketname, ListOptions.DEFAULT);
while (lr.hasNext() && playlistLength > 0) {
ListItem li = lr.next();
String filename = li.getName();
GcsService gcsService =
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(new GcsFilename(mybucketName, fileName), 0, 1024 * 1024);
AudioInputStream audioInputStream;
try (InputStream in = Channels.newInputStream(readChannel)) {
audioInputStream = AudioSystem.getAudioInputStream(in);
}
long frames = audioInputStream.getFrameLength();
double durationInSeconds = (frames+0.0) / format.getFrameRate();
playlistLength-=(int)(durationInSeconds)/60;
这是返回的错误:
Error for /hello java.lang.NoClassDefFoundError: javax.sound.sampled.AudioSystem is a restricted class.
Please see the Google App Engine developer's guide for more details.
at com.google.apphosting.runtime.security.shared.stub.javax.sound.sampled.AudioSystem.<clinit>(AudioSystem.java)
答案 0 :(得分:0)
在查看问题和文档here时,很有可能您的问题无法通过此库解决,因为它目前受到限制,因为它正在进行某种类型的系统调用平台不会让你这么做。
您可以使用多种解决方案。我建议,当您上传文件时,将实体上传到包含元数据的数据存储区并检索该元数据。
你也可以自己解析文件并从中读取持续时间(mp3是一种非常简单的格式,正如Igor Artamonov指出的那样)。