Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带webapi流的音频标记中的src从ResponseFlash获取songname_Javascript_Asp.net Web Api - Fatal编程技术网

Javascript 带webapi流的音频标记中的src从ResponseFlash获取songname

Javascript 带webapi流的音频标记中的src从ResponseFlash获取songname,javascript,asp.net-web-api,Javascript,Asp.net Web Api,我有一个带有html5音频标签的页面。src正在询问webapi控制器。控制器返回异步流,该流在音频标记中播放。 现在我添加了随机函数,希望显示歌曲标题。在控制器中,我在响应中添加了一个带有歌曲标题的responsephrase。 下面是HTML代码: <div id="audioControl" class="col-md-6"> <audio controls autoplay="autoplay" id="player"> <source id="

我有一个带有html5音频标签的页面。src正在询问webapi控制器。控制器返回异步流,该流在音频标记中播放。 现在我添加了随机函数,希望显示歌曲标题。在控制器中,我在响应中添加了一个带有歌曲标题的responsephrase。 下面是HTML代码:

<div id="audioControl" class="col-md-6">
  <audio controls autoplay="autoplay" id="player">
    <source id="audioSource" src='/api/Audio/mp3/' type='audio/mp3' />
    not supported
  </audio>
使用fiedler或浏览器的“网络”选项卡,我可以获得mp3的正确名称。现在我想使用javascript函数设置
标记的
src
,在这里我可以获得带有歌曲标题的ResponseFlash。 你知道怎么做吗

或者,唯一获得mp3名称的方法是使web api状态完整还是使用cookie

我的最新想法是将名称保存在服务器会话变量中,并通过另一个api调用获取名称。

找到了解决方案。 在控制器中:

var response = Request.CreateResponse();
FileInfo fileInfo = new FileInfo(rndPath[rndIndex]); //path of the mp3 
response.StatusCode = HttpStatusCode.OK;
response.ReasonPhrase = fileInfo.Name;
response.Content = new PushStreamContent
    (audio.WriteToStream, new   MediaTypeHeaderValue("audio/mp3"));
return response;
FileInfo fileInfo = new FileInfo(rndPath[rndIndex]); 
response.StatusCode = HttpStatusCode.OK;
response.ReasonPhrase = fileInfo.Name;
HttpContext.Current.Cache[User.Identity.Name] = fileInfo.Name;

response.Content = new PushStreamContent
  (audio.WriteToStream, new    MediaTypeHeaderValue("audio/mp3"));
return response;
 public class TitleController : ApiController
      {
        public string Get()
        {
          string title =(string)HttpContext.Current.Cache[User.Identity.Name.ToString()];

      return title;
    }
  }
Guess在打开2个浏览器窗口时不起作用。 添加了一个网元控制器:

var response = Request.CreateResponse();
FileInfo fileInfo = new FileInfo(rndPath[rndIndex]); //path of the mp3 
response.StatusCode = HttpStatusCode.OK;
response.ReasonPhrase = fileInfo.Name;
response.Content = new PushStreamContent
    (audio.WriteToStream, new   MediaTypeHeaderValue("audio/mp3"));
return response;
FileInfo fileInfo = new FileInfo(rndPath[rndIndex]); 
response.StatusCode = HttpStatusCode.OK;
response.ReasonPhrase = fileInfo.Name;
HttpContext.Current.Cache[User.Identity.Name] = fileInfo.Name;

response.Content = new PushStreamContent
  (audio.WriteToStream, new    MediaTypeHeaderValue("audio/mp3"));
return response;
 public class TitleController : ApiController
      {
        public string Get()
        {
          string title =(string)HttpContext.Current.Cache[User.Identity.Name.ToString()];

      return title;
    }
  }
在我看来

var aud = document.getElementById("player");
aud.onloadeddata = function ()
      {
        $.ajax({
          url: 'api/Title/',
          cache: false,
          async: false
        }).success(function (data)
        {
          $("#title").html(data);

    });
};