forked from microsoft/dotnet-podcasts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MauiWindow.cs
68 lines (58 loc) · 2.34 KB
/
MauiWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
namespace Microsoft.NetConf2021.Maui
{
class MauiWindow : Window
{
private PlayerService playerService;
public MauiWindow() : base() { }
public MauiWindow(Page page) : base(page) { }
protected override void OnCreated()
{
base.OnCreated();
if (playerService == null)
{
this.playerService = this.Handler.MauiContext.Services.GetService<PlayerService>();
}
if (Settings.EpisodeId != null)
{
var episode = new Episode()
{
Id = new Guid(Settings.EpisodeId),
Title = Settings.EpisodeTitle,
Description = Settings.EpisodeDescription,
Duration = Settings.EpisodeDuration,
Url = new Uri(Settings.EpisodeUrl),
Published = Settings.EpisodePublished
};
this.playerService.CurrentEpisode = episode;
Task.Run(async () =>
{
await this.playerService.resumeEpisode(Settings.CurrentPositionPlayer);
});
}
}
protected override void OnDestroying()
{
if (this.playerService.IsPlaying)
{
Settings.CurrentPositionPlayer = this.playerService.CurrentPosition;
Settings.EpisodeId = this.playerService.CurrentEpisode.Id.ToString();
Settings.EpisodeTitle = this.playerService.CurrentEpisode.Title;
Settings.EpisodeDescription = this.playerService.CurrentEpisode.Description;
Settings.EpisodeDuration = this.playerService.CurrentEpisode.Duration;
Settings.EpisodeUrl = this.playerService.CurrentEpisode.Url.OriginalString;
Settings.EpisodePublished = this.playerService.CurrentEpisode.Published;
}
else
{
Settings.CurrentPositionPlayer = 0.0;
Settings.EpisodeId = null;
Settings.EpisodeTitle = null;
Settings.EpisodeDescription = null;
Settings.EpisodeDuration = null;
Settings.EpisodeUrl = null;
Settings.EpisodePublished = new DateTime();
}
base.OnDestroying();
}
}
}