0

我一直在研究,但没有找到任何关于如何在 Android 应用程序上从 Azure 媒体服务播放音频流的教程?

我已经阅读了这些教程 http://azure.microsoft.com/en-us/documentation/articles/media-services-dotnet-get-started/ http://code.msdn.microsoft.com/Windows-Azure -Media-040435f8

但是他们下载资产而不是流式传输。

似乎有一个叫做 PlayReady 的东西,但我需要许可它!http://www.microsoft.com/playready/features/ClientOptions.aspx

谁能指导我任何代码/教程或从哪里开始,以便我可以播放上传到 Azure 媒体服务的音频流?

是否有可能我可以从 azure 媒体服务为我上传的音频文件获取流 url,然后我会在 Android 上使用 MediaPlayer API 正常播放?

4

2 回答 2

2

您可以使用 AMS REST API 或 SDK for .NET 上传 MP3 文件。

然后,您可以通过使用 Azure 媒体编码器进行编码并使用 AAC 优质音频预设来生成 MP4 文件。

确保添加至少一个点播流媒体单元。

以下示例使用 SDK for .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);
        }
    }
}

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

谢谢你,

朱莉娅

于 2014-11-19T22:43:08.147 回答
1

Azure 媒体服务旨在处理和提供流式视频,不支持纯音频媒体。

您可能想查看新的 Azure CDN 产品是否提供流畅的流式传输。

否则,真正启用此功能的唯一方法是设置可能在 Azure VM 上运行的适当流服务器,因为网站和 Web 角色 PaaS 产品没有内置流功能。

如果您需要公共云解决方案,您可能会考虑 AWS CloudFront Streaming 产品。

于 2014-07-08T02:06:13.270 回答