Skip to content

Commit b86fbb7

Browse files
committed
Code cleanup and fix for Windows
1 parent d578bb4 commit b86fbb7

2 files changed

Lines changed: 47 additions & 19 deletions

File tree

samples/CommunityToolkit.Maui.Sample.slnx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,19 @@
3434
<Deploy />
3535
</Project>
3636
</Folder>
37-
<Project Path="../src/CommunityToolkit.Maui.Camera/CommunityToolkit.Maui.Camera.csproj" />
38-
<Project Path="../src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj" />
39-
<Project Path="../src/CommunityToolkit.Maui.Maps/CommunityToolkit.Maui.Maps.csproj" />
40-
<Project Path="../src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj" />
41-
<Project Path="../src/CommunityToolkit.Maui/CommunityToolkit.Maui.csproj" />
37+
<Project Path="../src/CommunityToolkit.Maui.Camera/CommunityToolkit.Maui.Camera.csproj">
38+
<Deploy Solution="Debug|*" />
39+
</Project>
40+
<Project Path="../src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj">
41+
<Deploy Solution="Debug|*" />
42+
</Project>
43+
<Project Path="../src/CommunityToolkit.Maui.Maps/CommunityToolkit.Maui.Maps.csproj">
44+
<Deploy Solution="Debug|*" />
45+
</Project>
46+
<Project Path="../src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj">
47+
<Deploy Solution="Debug|*" />
48+
</Project>
49+
<Project Path="../src/CommunityToolkit.Maui/CommunityToolkit.Maui.csproj">
50+
<Deploy Solution="Debug|*" />
51+
</Project>
4252
</Solution>

samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementFromStreamPage.xaml.cs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
11
using System.ComponentModel;
22
using CommunityToolkit.Maui.Core;
33
using CommunityToolkit.Maui.Extensions;
4-
using CommunityToolkit.Maui.Sample.Constants;
54
using CommunityToolkit.Maui.Sample.ViewModels.Views;
65
using CommunityToolkit.Maui.Views;
76
using Microsoft.Extensions.Logging;
87

98
namespace CommunityToolkit.Maui.Sample.Pages.Views;
109

11-
public partial class MediaElementFromStreamPage : BasePage<MediaElementFromStreamViewModel>
10+
public partial class MediaElementFromStreamPage : BasePage<MediaElementFromStreamViewModel>, IDisposable
1211
{
13-
const string loadOnlineMp4 = "Load Online MP4";
14-
const string loadHls = "Load HTTP Live Stream (HLS)";
15-
const string loadLocalResource = "Load Local Resource";
16-
const string resetSource = "Reset Source to null";
17-
const string loadMusic = "Load Music";
18-
1912
const string botImageUrl = "https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm";
20-
const string hlsStreamTestUrl = "https://mtoczko.github.io/hls-test-streams/test-gap/playlist.m3u8";
21-
const string hal9000AudioUrl = "https://github.com/prof3ssorSt3v3/media-sample-files/raw/master/hal-9000.mp3";
2213

2314
readonly ILogger logger;
2415
readonly IDeviceInfo deviceInfo;
25-
readonly IFileSystem fileSystem;
2616

27-
MemoryStream sourceStream;
17+
MemoryStream? sourceStream;
18+
bool disposed;
2819

29-
public MediaElementFromStreamPage(MediaElementFromStreamViewModel viewModel, IFileSystem fileSystem, IDeviceInfo deviceInfo, ILogger<MediaElementPage> logger) : base(viewModel)
20+
public MediaElementFromStreamPage(MediaElementFromStreamViewModel viewModel, IDeviceInfo deviceInfo, ILogger<MediaElementPage> logger) : base(viewModel)
3021
{
3122
InitializeComponent();
3223

3324
this.logger = logger;
3425
this.deviceInfo = deviceInfo;
35-
this.fileSystem = fileSystem;
3626
MediaElement.PropertyChanged += MediaElement_PropertyChanged;
3727
}
3828

@@ -276,4 +266,32 @@ async void DisplayPopup(object? sender, EventArgs? e)
276266
popupMediaElement.Stop();
277267
popupMediaElement.Source = null;
278268
}
269+
270+
protected override void OnDisappearing()
271+
{
272+
base.OnDisappearing();
273+
sourceStream?.Dispose();
274+
}
275+
276+
public void Dispose()
277+
{
278+
Dispose(true);
279+
GC.SuppressFinalize(this);
280+
}
281+
282+
protected virtual void Dispose(bool disposing)
283+
{
284+
if (disposed)
285+
{
286+
return;
287+
}
288+
289+
if (disposing)
290+
{
291+
return;
292+
}
293+
294+
disposed = true;
295+
sourceStream?.Dispose();
296+
}
279297
}

0 commit comments

Comments
 (0)