Search code examples
google-chromeaudioazure-storage

Can't seek media in audio element in Chrome brower for audio in stored in Azure Blob


Able to play audio in chrome using audio element but when trying to seek(change the current playing time) it restarts playing from beginning of audio file.

Tried playing other file from FileStack and local file, it plays perfectly.


Solution

  • Check if HTTP request returns partial content for media, if not below is the investigation.

    File stack returns with below headers for audio file

    accept-ranges:bytes
    accept-ranges:bytes
    access-control-allow-headers:Content-Type, X-No-Stream
    access-control-allow-methods:DELETE, GET, HEAD, POST, PUT
    access-control-allow-origin:*
    access-control-max-age:21600
    age:5343
    cache-control:public, max-age=2678400
    content-disposition:inline; filename="8441b29c7dab61f5f38615330b744b59987846714763447555wav.mp3"
    content-length:316538
    content-range:bytes 0-316537/316538
    content-type:audio/mp3
    date:Mon, 25 Sep 2017 10:39:44 GMT
    etag:"1c3f5b13012a2edc4a74698dc6caf278"
    fastly-debug-digest:c89cb1c9d9747149691a99fe814c53edb54a470c54ea853578098f53d0974baf
    last-modified:Mon, 25 Sep 2017 09:10:40 GMT
    server:nginx
    **status:206**
    

    Azure blob returns

    Content-Length:316538
    Response of audio request
    Content-MD5:HD9bEwEqLtxKdGmNxsryeA==
    Content-Type:audio/mp3
    Date:Mon, 25 Sep 2017 10:39:43 GMT
    ETag:0x8D503FFF76724A4
    Last-Modified:Mon, 25 Sep 2017 10:27:04 GMT
    Server:Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
    x-ms-blob-type:BlockBlob
    x-ms-lease-status:unlocked
    x-ms-request-id:dcc6e80e-001e-0023-1dea-3532f0000000
    x-ms-version:2009-09-19 <- This is Azure Storage Service version
    status:200 <- Not a partial content
    

    Need to make Azure blob storage to return partial content (206).

    Referring

    1. Set Blob Service Properties - MSDN
    2. Streaming MP4 video files in Azure Storage containers (Blob Storage) - thoughtstuff

    Blob storage used was of a old version that did not support partial content. Verion used is mentioned in response header of HTTP request to media file "x-ms-version:2009-09-19". Need to make it use latest Azure Storage version.

    To set default Azure storage version

             // Retrieve storage account from connection-string
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
    
            // Create the blob client 
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    
            //Set Azure Storage Service version
            blobClient.GetServiceProperties();
            var properties = blobClient.GetServiceProperties();
            Trace.TraceInformation("Storage service version " + properties.DefaultServiceVersion);
            properties.DefaultServiceVersion = "2017-04-17";
            blobClient.SetServiceProperties(properties);
            Trace.TraceInformation("Storage service version " + properties.DefaultServiceVersion);
    

    On executing the above code once the default Azure Storage Version will be set to latest as of date and any HTTP request that does not explicitly specify any version to use will use default which in this case supports streaming partial content for media.