MP3 created from two others won't play in WMP11?

ε祈祈猫儿з 提交于 2019-12-11 08:54:41

问题


test1.mp3 and test2.mp3 have the same bitrate and sample rate, and I'm trying to merge them in an HTTP response. The resulting file is test.mp3.

test.mp3 plays fine in WMP12 and VLC. In WMP11, I hear only the audio which came from test1.mp3. At the moment you expect to hear the beginning of test2.mp3's audio, the player stops playing. WMP11 reports no errors... it just stops playing.

What needs to change such that test.mp3 will play correctly in WMP11?

protected void Page_Load(object sender, EventArgs e) {
    Response.Clear();
    Response.ContentType = "audio/mpeg";
    Response.AddHeader("Content-Disposition", "attachment; filename=test.mp3");
    var bytes1 = System.IO.File.ReadAllBytes(@"C:\test1.mp3");
    WriteBytesToResponse(bytes1);
    var bytes2 = System.IO.File.ReadAllBytes(@"C:\test2.mp3");
    WriteBytesToResponse(bytes2);
    Response.End();
}

private void WriteBytesToResponse(byte[] sourceBytes) {
    using (var sourceStream = new MemoryStream(sourceBytes, false)) {
        sourceStream.WriteTo(Response.OutputStream);
    }
}

回答1:


MP3 files contain a full MPEG1 header, amongst other information, such as the stream length. You simply cannot concatenate them. WMP read the header, determined the playback length, and stops when the first file is done. The rest of the data is ignored as it shouldn't be there.

You will need to use some library or utility which understands MPEG1 or MP3 files to do the concatenation.



来源:https://stackoverflow.com/questions/2099301/mp3-created-from-two-others-wont-play-in-wmp11

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!