Skip to content

Commit 37bf65f

Browse files
committed
* Swapping play/send duration order when reading/writing file properties object
* Pre-roll is stored in milliseconds * Fixing calculation of creation date to be based on 1/1/1601 * Checking more values in ASF format properties tests
1 parent d4a75ba commit 37bf65f

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/TaglibSharp.Tests/FileFormats/AsfFormatTest.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using NUnit.Framework;
23
using TagLib;
34

@@ -19,7 +20,12 @@ public void Init ()
1920
[Test]
2021
public void ReadAudioProperties ()
2122
{
22-
StandardTests.ReadAudioProperties (file);
23+
Assert.AreEqual (96, file.Properties.AudioBitrate);
24+
Assert.AreEqual (2, file.Properties.AudioChannels);
25+
Assert.AreEqual (44100, file.Properties.AudioSampleRate);
26+
// NOTE, with .net core it keeps the decimal places. So, for now, we round to match .net behavior
27+
Assert.AreEqual (4153, Math.Round(file.Properties.Duration.TotalMilliseconds));
28+
Assert.AreEqual (MediaTypes.Audio, file.Properties.MediaTypes);
2329
}
2430

2531
[Test]

src/TaglibSharp/Asf/FilePropertiesObject.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Brian Nickel ([email protected])
77
//
88
// Copyright (C) 2006-2007 Brian Nickel
9-
//
9+
//
1010
// This library is free software; you can redistribute it and/or modify
1111
// it under the terms of the GNU Lesser General Public License version
1212
// 2.1 as published by the Free Software Foundation.
@@ -33,6 +33,12 @@ namespace TagLib.Asf
3333
/// </summary>
3434
public class FilePropertiesObject : Object
3535
{
36+
#region Constant Values
37+
38+
static readonly DateTime FileTimeOffset = new DateTime (1601, 1, 1);
39+
40+
#endregion
41+
3642
#region Private Fields
3743

3844
/// <summary>
@@ -98,8 +104,8 @@ public FilePropertiesObject (File file, long position)
98104
FileSize = file.ReadQWord ();
99105
creation_date = file.ReadQWord ();
100106
DataPacketsCount = file.ReadQWord ();
101-
send_duration = file.ReadQWord ();
102107
play_duration = file.ReadQWord ();
108+
send_duration = file.ReadQWord ();
103109
Preroll = file.ReadQWord ();
104110
Flags = file.ReadDWord ();
105111
MinimumDataPacketSize = file.ReadDWord ();
@@ -144,7 +150,7 @@ public System.Guid FileId {
144150
/// date of the file described by the current instance.
145151
/// </value>
146152
public DateTime CreationDate {
147-
get { return new DateTime ((long)creation_date); }
153+
get { return new DateTime ((long)creation_date + FileTimeOffset.Ticks); }
148154
}
149155

150156
/// <summary>
@@ -253,8 +259,8 @@ public override ByteVector Render ()
253259
output.Add (RenderQWord (FileSize));
254260
output.Add (RenderQWord (creation_date));
255261
output.Add (RenderQWord (DataPacketsCount));
256-
output.Add (RenderQWord (send_duration));
257262
output.Add (RenderQWord (play_duration));
263+
output.Add (RenderQWord (send_duration));
258264
output.Add (RenderQWord (Preroll));
259265
output.Add (RenderDWord (Flags));
260266
output.Add (RenderDWord (MinimumDataPacketSize));

src/TaglibSharp/Asf/HeaderObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Brian Nickel ([email protected])
77
//
88
// Copyright (C) 2006-2007 Brian Nickel
9-
//
9+
//
1010
// This library is free software; you can redistribute it and/or modify
1111
// it under the terms of the GNU Lesser General Public License version
1212
// 2.1 as published by the Free Software Foundation.
@@ -144,7 +144,7 @@ public Properties Properties {
144144

145145
foreach (var obj in Children) {
146146
if (obj is FilePropertiesObject fpobj) {
147-
duration = fpobj.PlayDuration - new TimeSpan ((long)fpobj.Preroll);
147+
duration = fpobj.PlayDuration - TimeSpan.FromMilliseconds (fpobj.Preroll);
148148
continue;
149149
}
150150

0 commit comments

Comments
 (0)