【问题标题】:Stream MP3 files with Microsoft Azure使用 Microsoft Azure 流式传输 MP3 文件
【发布时间】:2015-09-20 02:38:00
【问题描述】:
是否可以使用 Microsoft Azure 流式传输 MP3 或 WAV 文件?
我想要一个可以与任何 js 播放器一起播放的文件,包括从用户想要的任何点开始播放(如 soundcloud 播放器,...)。
我尝试为此使用 Blob 存储,但这是不可能的,因为它确实支持流式传输,因此必须完全下载文件才能跳转到歌曲的某个点。
有没有办法通过 Blob 存储实现这一点?还是我必须使用 Azure 媒体服务(尝试过,但只找到了对视频的支持)?
【问题讨论】:
标签:
azure
stream
blob
mp3
storage
【解决方案1】:
这里的问题是存储的服务版本。我必须通过 Java 程序手动将其设置为更高版本(2014-02-14)。
这里是代码。您需要 azure SDK (https://github.com/Azure/azure-sdk-for-java) 以及 slf4j、lang3 和 fasterxml 库。
import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.ServiceProperties;
public class storage {
public static void main(String[] args) {
CloudStorageAccount storageAccount;
ServiceProperties serviceProperties;
try {
storageAccount = CloudStorageAccount.parse("AccountName=<storageName>;AccountKey=<storageAccessKey>;DefaultEndpointsProtocol=http");
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// Get the current service properties
serviceProperties = blobClient.downloadServiceProperties();
// Set the default service version to 2011-08-18 (or a higher version like 2012-03-01)
serviceProperties.setDefaultServiceVersion("2014-02-14");
// Save the updated service properties
blobClient.uploadServiceProperties(serviceProperties);
} catch(Exception e) {
System.out.print("Exception");
}
};
};