Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASF Duration Calculation Fix, Creation Date Fix #256

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/TaglibSharp.Tests/FileFormats/AsfFormatTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using NUnit.Framework;
using TagLib;

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

[Test]
Expand Down
14 changes: 10 additions & 4 deletions src/TaglibSharp/Asf/FilePropertiesObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Brian Nickel ([email protected])
//
// Copyright (C) 2006-2007 Brian Nickel
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
Expand All @@ -33,6 +33,12 @@ namespace TagLib.Asf
/// </summary>
public class FilePropertiesObject : Object
{
#region Constant Values

static readonly DateTime FileTimeOffset = new DateTime (1601, 1, 1);

#endregion

#region Private Fields

/// <summary>
Expand Down Expand Up @@ -98,8 +104,8 @@ public FilePropertiesObject (File file, long position)
FileSize = file.ReadQWord ();
creation_date = file.ReadQWord ();
DataPacketsCount = file.ReadQWord ();
send_duration = file.ReadQWord ();
play_duration = file.ReadQWord ();
send_duration = file.ReadQWord ();
Preroll = file.ReadQWord ();
Flags = file.ReadDWord ();
MinimumDataPacketSize = file.ReadDWord ();
Expand Down Expand Up @@ -144,7 +150,7 @@ public System.Guid FileId {
/// date of the file described by the current instance.
/// </value>
public DateTime CreationDate {
get { return new DateTime ((long)creation_date); }
get { return new DateTime ((long)creation_date + FileTimeOffset.Ticks); }
}

/// <summary>
Expand Down Expand Up @@ -253,8 +259,8 @@ public override ByteVector Render ()
output.Add (RenderQWord (FileSize));
output.Add (RenderQWord (creation_date));
output.Add (RenderQWord (DataPacketsCount));
output.Add (RenderQWord (send_duration));
output.Add (RenderQWord (play_duration));
output.Add (RenderQWord (send_duration));
output.Add (RenderQWord (Preroll));
output.Add (RenderDWord (Flags));
output.Add (RenderDWord (MinimumDataPacketSize));
Expand Down
4 changes: 2 additions & 2 deletions src/TaglibSharp/Asf/HeaderObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Brian Nickel ([email protected])
//
// Copyright (C) 2006-2007 Brian Nickel
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
Expand Down Expand Up @@ -144,7 +144,7 @@ public Properties Properties {

foreach (var obj in Children) {
if (obj is FilePropertiesObject fpobj) {
duration = fpobj.PlayDuration - new TimeSpan ((long)fpobj.Preroll);
duration = fpobj.PlayDuration - TimeSpan.FromMilliseconds (fpobj.Preroll);
continue;
}

Expand Down