Block download in an audio streaming

Asked

Viewed 248 times

0

I have a Web MVC application in which it resumes an audio stream according to the received parameters:

public new ActionResult File(string q, string url)
    {
        try
        {
            var query = new GetFileQuery()
            {
                q = q.Substring(0, 8),
                sequencial = q.Substring(8),
                path = url
            };

            if (query.q == query.Hash1)
            {
                string contentType = MimeMapping.GetMimeMapping(query.fileName);

                var cd = new System.Net.Mime.ContentDisposition
                {
                    FileName = query.fileName,
                    Inline = true,
                };

                Response.AppendHeader("Content-Disposition", cd.ToString());

                query.ConvertWavMP3(query.path);

                 File(
                    query.fileBytes
                    , contentType);

            }
        }
        catch (Exception e)
        {

        }
        return View("Index");
    }

However I need that this audio is only for viewing without the download option and the same is in a tag audio, as I call this file on tag and lock the download option?

  • What do you mean, "for viewing only" ?

  • It would be without the option to download only stream as well as youtube with videos.

  • your code is more to download even than stream.. take a look at this link you will get help: transmitting-audio-video

1 answer

1


To remove the audio tag download option you can use controlsList="nodownload" see documentation. However, this does not guarantee that the download will be done.

<div id="player">
  <audio id="audio" src="https://upload.wikimedia.org/wikipedia/commons/8/8f/Fur_Elise.ogg" controls controlsList="nodownload"></audio>
</div>

  • Sensational! But, how do I implement the controller to insert the audio path to that tag ? I have to create a view?

  • That’s it. However, if you want to stream audio you’ll have to do it in the web api. Here is a tutorial: https://www.strathweb.com/2013/01/asynchronously-streaming-video-with-asp-net-web-api/. What you can do is bring your audio file or the url of it where it is hosted and insert it in the audio tag: <audio id="audio" src="@model.urlAudio" Controls controlsList="nodownload"></audio>

  • Dude I can’t put src in the audio path on the server ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.