我正在尝试使用 HTML5 重现音频,但有时无法重现 Ogg 文件,这是我的服务器(BasicHandler.ashx)中的配置:
string oggFileName = @"C:\Users\gustav\Desktop\Player\Files\TestAudio.ogg";
byte[] bytes = File.ReadAllBytes(oggFileName);
httpContext.Response.ContentType = "audio/ogg";
httpContext.Response.AddHeader("pragma", "Public");
httpContext.Response.AddHeader("Accept-Ranges", "bytes");
httpContext.Response.Cache.SetCacheability(HttpCacheability.Public);
httpContext.Response.Cache.SetLastModified(new DateTime(2000, 01, 01));
httpContext.Response.Cache.SetExpires(new DateTime(2020, 01, 01));
httpContext.Response.BinaryWrite(bytes);
我的播放器有这个代码:
<div id="Player">
<audio id="audioPlayer" preload="auto" controls onplay="ReloadPlayer()">
<source src="http://localhost:4677/Services/BasicHandler.ashx" type="audio/ogg">
Your browser does not support the audio element.frff
</audio>
该播放器与音频 MP3 或 MP4 (AAC) 完美配合,但当我尝试使用 Ogg 时,无法播放音频(在 Firefox 中有效,但在 Chrome 中是问题)。对这个问题有任何想法吗?