MP3 created from two others won't play in WMP1

2019-07-31 18:49发布

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条回答
手持菜刀,她持情操
2楼-- · 2019-07-31 19:45

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.

查看更多
登录 后发表回答