Skip to content

Commit 7c46c3d

Browse files
authored
Implement [BindableProperty] for MediaElement (#2933)
1 parent 69d887e commit 7c46c3d

File tree

17 files changed

+782
-416
lines changed

17 files changed

+782
-416
lines changed

samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementCarouselViewPage.xaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Text="This page demonstrates that the MediaElement can be used inside of a DataTemplate"
1919
Margin="12,0,12,0"/>
2020
<CarouselView HeightRequest="275" PeekAreaInsets="52" ItemsSource="{Binding ItemSource}">
21-
21+
2222
<CarouselView.ItemsLayout>
2323
<LinearItemsLayout Orientation="Horizontal"
2424
ItemSpacing="24"
@@ -55,18 +55,18 @@
5555
</Border>
5656
</DataTemplate>
5757
</CarouselView.ItemTemplate>
58-
58+
5959
</CarouselView>
60-
60+
6161
<Label HorizontalTextAlignment="Center"
6262
VerticalTextAlignment="Center"
6363
HorizontalOptions="Center"
6464
VerticalOptions="Center"
6565
Text="Second CarouselView to confirm MediaElement can be used on a Page containing multiple ItemsView controls"
6666
Margin="12,0,12,0"/>
67-
67+
6868
<CarouselView HeightRequest="275" PeekAreaInsets="52" ItemsSource="{Binding ItemSource}">
69-
69+
7070
<CarouselView.ItemsLayout>
7171
<LinearItemsLayout Orientation="Horizontal"
7272
ItemSpacing="24"
@@ -102,15 +102,15 @@
102102
</Border>
103103
</DataTemplate>
104104
</CarouselView.ItemTemplate>
105-
105+
106106
</CarouselView>
107-
107+
108108
<Label Text="Swipe Left or Right to see next video"
109109
HorizontalOptions="Center"
110110
VerticalOptions="Center"
111111
HorizontalTextAlignment="Center"
112112
VerticalTextAlignment="Center"
113113
FontAttributes="Italic"/>
114-
114+
115115
</VerticalStackLayout>
116116
</pages:BasePage>

samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementCollectionViewPage.xaml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,55 @@
1010
Padding="0, 20, 0, 0"
1111
Title="MediaElement in CollectionView">
1212
<ScrollView>
13-
<VerticalStackLayout Spacing="12">
14-
<Label HorizontalTextAlignment="Center"
13+
<VerticalStackLayout Spacing="12">
14+
<Label HorizontalTextAlignment="Center"
1515
VerticalTextAlignment="Center"
1616
HorizontalOptions="Center"
1717
VerticalOptions="Center"
1818
Text="This page demonstrates that the MediaElement can be used inside of a DataTemplate"
1919
Margin="12,0,12,0"/>
20-
<CollectionView HeightRequest="850" ItemsSource="{Binding ItemSource}">
21-
22-
<CollectionView.ItemsLayout>
23-
<GridItemsLayout Orientation="Vertical"
20+
<CollectionView HeightRequest="850" ItemsSource="{Binding ItemSource}">
21+
22+
<CollectionView.ItemsLayout>
23+
<GridItemsLayout Orientation="Vertical"
2424
Span="1"
2525
SnapPointsAlignment="Center"
2626
SnapPointsType="MandatorySingle" />
27-
</CollectionView.ItemsLayout>
27+
</CollectionView.ItemsLayout>
2828

29-
<CollectionView.ItemTemplate>
30-
<DataTemplate x:DataType="viewModels:MediaElementDataSource">
31-
<Border
29+
<CollectionView.ItemTemplate>
30+
<DataTemplate x:DataType="viewModels:MediaElementDataSource">
31+
<Border
3232
x:Name="CollectionViewBorder"
3333
BackgroundColor="Black"
3434
Padding="5">
35-
<Border.StrokeShape>
36-
<RoundRectangle CornerRadius="4" />
37-
</Border.StrokeShape>
38-
<VerticalStackLayout Spacing="6" HeightRequest="250">
39-
<toolkit:MediaElement
35+
<Border.StrokeShape>
36+
<RoundRectangle CornerRadius="4" />
37+
</Border.StrokeShape>
38+
<VerticalStackLayout Spacing="6" HeightRequest="250">
39+
<toolkit:MediaElement
4040
HeightRequest="200"
4141
x:Name="MediaElement"
4242
ShouldAutoPlay="True"
4343
ShouldShowPlaybackControls="True"
4444
Source="{Binding Source, Mode=OneTime}" />
45-
<Label TextColor="White"
45+
<Label TextColor="White"
4646
HorizontalOptions="Center"
4747
VerticalOptions="Center"
4848
HorizontalTextAlignment="Center"
4949
VerticalTextAlignment="Center"
5050
FontAttributes="Bold"
5151
FontSize="18"
5252
Text="{Binding Name, Mode=OneTime}"/>
53-
</VerticalStackLayout>
54-
</Border>
55-
</DataTemplate>
56-
</CollectionView.ItemTemplate>
57-
58-
</CollectionView>
59-
60-
</VerticalStackLayout>
61-
53+
</VerticalStackLayout>
54+
</Border>
55+
</DataTemplate>
56+
</CollectionView.ItemTemplate>
57+
58+
</CollectionView>
59+
60+
</VerticalStackLayout>
61+
6262
</ScrollView>
63-
63+
6464
</pages:BasePage>

src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@
4747
<Configurations>Debug;Release</Configurations>
4848
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors>
4949
<GenerateDocumentationFile>True</GenerateDocumentationFile>
50+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
51+
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
5052
</PropertyGroup>
5153

5254
<ItemGroup>
5355
<None Include="..\..\build\nuget.png" PackagePath="icon.png" Pack="true" />
5456
<None Include="ReadMe.txt" pack="true" PackagePath="." />
5557
</ItemGroup>
56-
58+
59+
<ItemGroup>
60+
<ProjectReference Include="..\CommunityToolkit.Maui.SourceGenerators.Internal\CommunityToolkit.Maui.SourceGenerators.Internal.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
61+
</ItemGroup>
62+
5763
<ItemGroup>
5864
<None Include="..\CommunityToolkit.Maui.MediaElement.Analyzers\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Maui.MediaElement.Analyzers.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
5965
<None Include="..\CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />

src/CommunityToolkit.Maui.MediaElement/Interfaces/IMediaElement.shared.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@ namespace CommunityToolkit.Maui.Core;
99
public interface IMediaElement : IView, IAsynchronousMediaElementHandler
1010
{
1111
/// <summary>
12-
/// Gets or sets the title of the media.
13-
/// </summary>
14-
string MetadataTitle { get; set; }
15-
16-
/// <summary>
17-
/// Gets or sets the artist of the media.
12+
/// Occurs when <see cref="CurrentState"/> changed.
1813
/// </summary>
19-
string MetadataArtist { get; set; }
14+
event EventHandler<MediaStateChangedEventArgs> StateChanged;
2015

2116
/// <summary>
22-
/// Gets or sets the artwork Image Url.
17+
/// Occurs when the <see cref="Position"/> changes;
2318
/// </summary>
24-
string MetadataArtworkUrl { get; set; }
25-
19+
event EventHandler<MediaPositionChangedEventArgs> PositionChanged;
20+
2621
/// <summary>
2722
/// Gets the media aspect ratio.
2823
/// </summary>
@@ -98,18 +93,23 @@ public interface IMediaElement : IView, IAsynchronousMediaElementHandler
9893
/// <summary>
9994
/// Gets or sets the volume of the audio for the media.
10095
/// </summary>
101-
/// <remarks>A value of 1 means full volume, 0 is silence.</remarks>
96+
/// <remarks>A value of 1 indicates full volume, 0 is silence.</remarks>
10297
double Volume { get; set; }
98+
99+
/// <summary>
100+
/// Gets or sets the title of the media.
101+
/// </summary>
102+
string MetadataTitle { get; set; }
103103

104104
/// <summary>
105-
/// Occurs when <see cref="CurrentState"/> changed.
105+
/// Gets or sets the artist of the media.
106106
/// </summary>
107-
event EventHandler<MediaStateChangedEventArgs> StateChanged;
107+
string MetadataArtist { get; set; }
108108

109109
/// <summary>
110-
/// Occurs when the <see cref="Position"/> changes;
110+
/// Gets or sets the artwork Image Url.
111111
/// </summary>
112-
event EventHandler<MediaPositionChangedEventArgs> PositionChanged;
112+
string MetadataArtworkUrl { get; set; }
113113

114114
/// <summary>
115115
/// Occurs when the media has ended playing successfully.

0 commit comments

Comments
 (0)