简体   繁体   English

如何:使用Azure Media Services在Android上流音频?

[英]How to: Stream Audio on Android using Azure Media Services?

I've been researching but didn't find any tutorial on how to play an audio stream from Azure Media Services on Android apps ? 我一直在研究,但是没有找到有关如何在Android应用程序上播放Azure Media Services音频流的任何教程?

I've went through those tutorials http://azure.microsoft.com/en-us/documentation/articles/media-services-dotnet-get-started/ http://code.msdn.microsoft.com/Windows-Azure-Media-040435f8 我已经遍历了这些教程http://azure.microsoft.com/zh-cn/documentation/articles/media-services-dotnet-get-started/ http://code.msdn.microsoft.com/Windows-Azure -媒体-040435f8

But they download an asset not stream it. 但是他们下载资产而不是流式传输。

There seems to be sth called PlayReady, but I need to license it !! 似乎有一个叫做PlayReady的东西,但是我需要许可它! http://www.microsoft.com/playready/features/ClientOptions.aspx http://www.microsoft.com/playready/features/ClientOptions.aspx

Can anyone guide me to any code/tutorial or where to start such that I could play an audio stream uploaded on Azure Media Services ? 任何人都可以将我引导至任何代码/教程或从何处开始,以便我可以播放在Azure媒体服务上上传的音频流吗?

Is it possible that I could obtain a streaming url from azure media services for my uploaded audio file, and then I would just play that normally using the MediaPlayer API on Android ? 是否有可能我可以从azure媒体服务中获取用于上传的音频文件的流URL,然后我通常可以使用Android上的MediaPlayer API正常播放该URL?

You can use AMS REST API or SDK for .NET to upload an MP3 file. 您可以使用AMS REST API或.NET SDK上载MP3文件。

You can then produce an MP4 file by encoding with Azure Media Encoder and using the AAC Good Quality Audio preset. 然后,您可以通过使用Azure Media Encoder进行编码并使用AAC高质量音频预设来生成MP4文件。

Make sure to add at least one On-Demand streaming unit. 确保至少添加一个按需流媒体单元。

The following example uses SDK for .NET Extensions. 下面的示例将SDK用于.NET Extensions。

 using System; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; using System.Net; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using Microsoft.WindowsAzure.MediaServices.Client; using System.Threading; namespace AudioTest { class Program { // Read values from the App.config file. private static readonly string _mediaServicesAccountName = ConfigurationManager.AppSettings["MediaServicesAccountName"]; private static readonly string _mediaServicesAccountKey = ConfigurationManager.AppSettings["MediaServicesAccountKey"]; // Field for service context. private static CloudMediaContext _context = null; private static MediaServicesCredentials _cachedCredentials = null; static void Main(string[] args) { // Create and cache the Media Services credentials in a static class variable. _cachedCredentials = new MediaServicesCredentials( _mediaServicesAccountName, _mediaServicesAccountKey); // Used the cached credentials to create CloudMediaContext. _context = new CloudMediaContext(_cachedCredentials); // 1. Create a new asset by uploading a mezzanine file from a local path. IAsset inputAsset = _context.Assets.CreateFromFile( @"testrecording.wma", AssetCreationOptions.None, (af, p) => { Console.WriteLine("Uploading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress); }); IJob job = _context.Jobs.CreateWithSingleTask( MediaProcessorNames.AzureMediaEncoder, MediaEncoderTaskPresetStrings.AACGoodQualityAudio, inputAsset, "AACGoodQualityAudio", AssetCreationOptions.None); Console.WriteLine("Submitting transcoding job..."); // 3. Submit the job and wait until it is completed. job.Submit(); job = job.StartExecutionProgressTask( j => { Console.WriteLine("Job state: {0}", j.State); Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress()); }, CancellationToken.None).Result; Console.WriteLine("Transcoding job finished."); IAsset outputAsset = job.OutputMediaAssets[0]; Console.WriteLine("Publishing output asset..."); // 4. Publish the output asset by creating an Origin locator for adaptive streaming. _context.Locators.Create( LocatorType.OnDemandOrigin, outputAsset, AccessPermissions.Read, TimeSpan.FromDays(30)); Uri hlsUri = outputAsset.GetHlsUri(); Uri mpegDashUri = outputAsset.GetMpegDashUri(); // 6. Get the asset URLs. // Test HLS with Safari and Chrome on iOS. Console.WriteLine(hlsUri); // Test MPEG DASH with http://dashif.org/reference/players/javascript/ Console.WriteLine(mpegDashUri); } } } 

Also, see https://social.msdn.microsoft.com/Forums/azure/en-US/4fb146f1-81f4-4da0-a157-3e2316b127fe/windows-azure-media-services-audio-only?forum=MediaServices . 另外,请参阅https://social.msdn.microsoft.com/Forums/azure/zh-CN/4fb146f1-81f4-4da0-a157-3e2316b127fe/windows-azure-media-services-audio-only?forum=MediaServices

thank you, 谢谢,

Julia 朱莉亚

Azure Media Services is designed to process and serve streamed video and doesn't support audio-only media. Azure Media Services旨在处理和提供流视频,并且不支持纯音频媒体。

You might want to check to see if the new Azure CDN offering is providing smooth streaming yet. 您可能要检查新的Azure CDN产品是否正在提供流畅的流。

Otherwise the only way to really enable this would be to setup an appropriate streaming server potentially running on an Azure VM as the websites and web role PaaS offerings don't have streaming capabilities baked into them. 否则,真正启用此功能的唯一方法是设置适当的流服务器,该服务器可能在Azure VM上运行,因为网站和Web角色PaaS产品没有内置流功能。

Failing this you could potentially look at the AWS CloudFront Streaming offering if you need a public cloud solution. 失败的话,如果您需要公共云解决方案,则可以潜在地查看AWS CloudFront Streaming产品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM