一個專案中用到了音瞥澩播放,使用的是html5的audio組件,根據網上查詢的資料 此組件需要根據不同瀏覽器使用不同的音頻格式的檔案。
如:
<audio controls="controls" id="audioControl">
<source class="mp3" src="">
<source class="ogg" src="">
<source class="wav" src="" />
</audio>
本人通過JS為組件里的各類音頻賦值了對應的檔案流地址:
$('#audioControl .mp3').attr('src', baseApiUrl + '/ArticleInfo/DownloadArticle?id=' + id + '&idSign=' + downSign);
$('#audioControl .ogg').attr('src', baseApiUrl + '/ArticleInfo/DownloadArticle?id=' + id + '&fileType=ogg&idSign=' + downSign);
$('#audioControl .wav').attr('src', baseApiUrl + '/ArticleInfo/DownloadArticle?id=' + id + '&fileType=wav&idSign=' + downSign);
document.getElementById('audioControl').load();后端代碼如下(.netcore)
var filePath = UploadConfig.DataTypePDFPath + model.Pdfpath;
if (fileType == "ogg")//獲取音頻OGG格式
filePath = filePath.ToLower().Replace(".mp3", ".ogg");
if (fileType == "wav")//獲取音頻OGG格式
filePath = filePath.ToLower().Replace(".mp3", ".wav");
FileInfo fileInfo = new FileInfo(filePath);
if (!fileInfo.Exists)
{
return ErrorInfo("檔案不存在!");
}
var ext = fileInfo.Extension;
new FileExtensionContentTypeProvider().Mappings.TryGetValue(ext, out var contenttype);
return File(System.IO.File.ReadAllBytes(filePath), contenttype ?? "application/octet-stream", fileInfo.Name);
在谷歌瀏覽器播放正常,但在本人的IE(IE11)以及火狐(81.0.2【最新】)均播放失敗
火狐瀏覽器播放的時候提示解碼失敗

IE瀏覽器里提示型別不支持或檔案路徑無效

其中火狐瀏覽器里解碼問題在網上找到一種解決方案是重啟Windows音頻服務,用CMD命令重啟后重啟火狐瀏覽器依然不行。(https://stackoom.com/question/31tXs/Firefox-HTML-%E9%9F%B3%E9%A2%91-%E5%AA%92%E4%BD%93%E8%B5%84%E6%BA%90%E6%97%A0%E6%B3%95%E8%A7%A3%E7%A0%81-OnMediaSinkAudioError)
也去找過jquery音頻插件,插件官方樣例但也是一樣的問題。(https://www.jq22.com/yanshi419)
火狐瀏覽器也是提示:
媒體資源 https://www.jq22.com/demo/bofq/audio.mp3 無法被解碼。
媒體資源 https://www.jq22.com/demo/bofq/audio.ogg 無法被解碼。
媒體資源 https://www.jq22.com/demo/bofq/audio.wav 無法被解碼。
求一個解決方案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/185141.html
標籤:ASP.NET
上一篇:如何關閉FileStrem?
下一篇:如何獲取磁盤驅動名稱?
