【问题标题】:Getting mp3 duration storaged in google app engine cloud storage将 mp3 持续时间存储在谷歌应用引擎云存储中
【发布时间】:2015-08-03 09:41:10
【问题描述】:

我在 Google App Engine Cloud Storage 中存储了 mp3 文件,我想获取它们的持续时间。 我在这里的一个人的帮助下编写了这段代码,但不幸的是,AudioSystem 类不适用于 Google App Engine Cloud Storage。 有人知道怎么做吗?

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.AudioSyst‌​em.<clinit>(AudioSystem.java)

【问题讨论】:

  • “不起作用”是什么意思?我们需要更多信息。
  • 这就是我从堆栈跟踪中获得的全部信息:/hello java.lang.NoClassDefFoundError 的错误:javax.sound.sampled.AudioSystem 是一个受限类。有关详细信息,请参阅 Google App Engine 开发人员指南。
  • 那么.....在来这里之前,您是否查看了谷歌应用引擎开发人员指南以了解更多详细信息? :)
  • 是的。而且我找不到其他方法。
  • 那么,你从“受限类”中得到了什么信息?它应该指出它为什么不起作用,然后您可以根据它不起作用的原因推断您的解决方案

标签: google-app-engine servlets mp3 google-cloud-storage duration


【解决方案1】:

查看问题和文档here,您的问题很可能无法通过此库解决,因为它目前受到限制,因为它正在执行某种平台不允许您执行的系统调用。

您可以使用多种解决方案。我建议,当您上传文件时,将实体上传到包含元数据的数据存储区并取而代之的是检索它。

您也可以自己解析文件并从中读取持续时间(mp3 是一种非常简单的格式,正如Igor Artamonov 所指出的那样)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-09
    • 2014-10-30
    • 2013-05-17
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    • 2012-10-13
    • 1970-01-01
    相关资源
    最近更新 更多