Skip to content

Commit d2652a4

Browse files
authored
Feature: Added audio bitrate to the Details Pane (#15304)
1 parent acd8803 commit d2652a4

File tree

6 files changed

+37
-28
lines changed

6 files changed

+37
-28
lines changed

src/Files.App/Assets/Resources/PreviewPanePropertiesInformation.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@
184184
"IsReadOnly": false,
185185
"ID": null
186186
},
187+
{
188+
"NameResource": "PropertyPreviewAudioEncodingBitrate",
189+
"SectionResource": "PropertySectionAudio",
190+
"Property": "System.Audio.EncodingBitrate",
191+
"IsReadOnly": true,
192+
"DisplayFunctionName": "FormatEncodingBitrate",
193+
"ID": null
194+
},
195+
{
196+
"NameResource": "PropertyPreviewVideoEncodingBitrate",
197+
"SectionResource": "PropertySectionVideo",
198+
"Property": "System.Video.EncodingBitrate",
199+
"IsReadOnly": true,
200+
"DisplayFunctionName": "FormatEncodingBitrate",
201+
"ID": null
202+
},
187203
{
188204
"NameResource": "PropertyDuration",
189205
"SectionResource": "PropertySectionMedia",

src/Files.App/Assets/Resources/PropertiesInformation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
"SectionResource": "PropertySectionAudio",
161161
"Property": "System.Audio.EncodingBitrate",
162162
"IsReadOnly": true,
163+
"DisplayFunctionName": "FormatEncodingBitrate",
163164
"ID": null
164165
},
165166
{
@@ -499,6 +500,7 @@
499500
"SectionResource": "PropertySectionVideo",
500501
"Property": "System.Video.EncodingBitrate",
501502
"IsReadOnly": true,
503+
"DisplayFunctionName": "FormatEncodingBitrate",
502504
"ID": null
503505
},
504506
{

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,12 @@
882882
<data name="PropertyEncodingBitrate" xml:space="preserve">
883883
<value>Encoding Bitrate</value>
884884
</data>
885+
<data name="PropertyPreviewAudioEncodingBitrate" xml:space="preserve">
886+
<value>Audio Encoding Bitrate</value>
887+
</data>
888+
<data name="PropertyPreviewVideoEncodingBitrate" xml:space="preserve">
889+
<value>Video Encoding Bitrate</value>
890+
</data>
885891
<data name="Compression" xml:space="preserve">
886892
<value>Compression</value>
887893
</data>

src/Files.App/ViewModels/Properties/Items/CombinedFileProperties.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@ await LocationHelpers.GetAddressFromCoordinatesAsync((double?)list.Find(
3232
x => x.Property == "System.GPS.LatitudeDecimal").Value,
3333
(double?)list.Find(x => x.Property == "System.GPS.LongitudeDecimal").Value);
3434

35-
// Find Encoding Bitrate property and convert it to kbps
36-
var encodingBitrate = list.Find(x => x.Property == "System.Audio.EncodingBitrate");
37-
38-
if (encodingBitrate?.Value is null)
39-
encodingBitrate = list.Find(x => x.Property == "System.Video.EncodingBitrate");
40-
41-
if (encodingBitrate?.Value is not null)
42-
{
43-
var sizes = new string[] { "Bps", "KBps", "MBps", "GBps" };
44-
var order = (int)Math.Floor(Math.Log((uint)encodingBitrate.Value, 1024));
45-
var readableSpeed = (uint)encodingBitrate.Value / Math.Pow(1024, order);
46-
encodingBitrate.Value = $"{readableSpeed:0.##} {sizes[order]}";
47-
}
48-
4935
return list
5036
.Where(fileProp => !(fileProp.Value is null && fileProp.IsReadOnly))
5137
.GroupBy(fileProp => fileProp.SectionResource)

src/Files.App/ViewModels/Properties/Items/FileProperties.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,6 @@ await LocationHelpers.GetAddressFromCoordinatesAsync((double?)list.Find(
170170
x => x.Property == "System.GPS.LatitudeDecimal").Value,
171171
(double?)list.Find(x => x.Property == "System.GPS.LongitudeDecimal").Value);
172172

173-
// Find Encoding Bitrate property and convert it to kbps
174-
var encodingBitrate = list.Find(x => x.Property == "System.Audio.EncodingBitrate");
175-
176-
if (encodingBitrate?.Value is null)
177-
encodingBitrate = list.Find(x => x.Property == "System.Video.EncodingBitrate");
178-
179-
if (encodingBitrate?.Value is not null)
180-
{
181-
var sizes = new string[] { "Bps", "KBps", "MBps", "GBps" };
182-
var order = Math.Min((int)Math.Floor(Math.Log((uint)encodingBitrate.Value, 1024)), 3);
183-
var readableSpeed = (uint)encodingBitrate.Value / Math.Pow(1024, order);
184-
encodingBitrate.Value = $"{readableSpeed:0.##} {sizes[order]}";
185-
}
186-
187173
var query = list
188174
.Where(fileProp => !(fileProp.Value is null && fileProp.IsReadOnly))
189175
.GroupBy(fileProp => fileProp.SectionResource)

src/Files.App/ViewModels/Properties/Items/FileProperty.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,22 @@ public async static Task<List<FileProperty>> RetrieveAndInitializePropertiesAsyn
363363
{ "AddISO" , input => $"ISO-{(UInt16)input}"},
364364
{ "RoundDouble" , input => $"{Math.Round((double)input)}"},
365365
{ "UnitMM" , input => $"{(double)input} mm"},
366+
{ "FormatEncodingBitrate", FormatEncodingBitrate }
366367
};
367368

368369
private static string TimeSpanToString(TimeSpan t)
369370
=> t.Days > 0 ? (t.Days * 24 + t.Hours) + t.ToString("':'mm':'ss") : t.ToString("hh':'mm':'ss");
371+
372+
private static string FormatEncodingBitrate(object input)
373+
{
374+
// For cases when multiple files are selected and it has a string value
375+
if (input.GetType() != typeof(uint))
376+
return input?.ToString() ?? string.Empty;
377+
378+
var sizes = new string[] { "bps", "kbps", "Mbps", "Gbps" };
379+
var order = (int)Math.Floor(Math.Log((uint)input, 1000));
380+
var readableSpeed = (uint)input / Math.Pow(1000, order);
381+
return $"{readableSpeed:0.##} {sizes[order]}";
382+
}
370383
}
371384
}

0 commit comments

Comments
 (0)