Skip to content

Commit e009ed4

Browse files
Merge branch 'main' into feature/sl/remove-popup-constraint-from-popup-service
2 parents 5f596b9 + 12adc49 commit e009ed4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+298
-167
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace CommunityToolkit.Maui.Sample.Constants;
2+
3+
static class StreamingVideoUrls
4+
{
5+
public const string BuckBunny = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
6+
public const string ElephantsDream = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4";
7+
public const string Sintel = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4";
8+
}

samples/CommunityToolkit.Maui.Sample/MauiProgram.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics.CodeAnalysis;
22
using CommunityToolkit.Maui.ApplicationModel;
3+
using CommunityToolkit.Maui.Core;
34
using CommunityToolkit.Maui.Markup;
45
using CommunityToolkit.Maui.Media;
56
using CommunityToolkit.Maui.Sample.Pages;
@@ -25,6 +26,7 @@
2526
using CommunityToolkit.Maui.Sample.ViewModels.Views;
2627
using CommunityToolkit.Maui.Sample.Views.Popups;
2728
using CommunityToolkit.Maui.Storage;
29+
using CommunityToolkit.Maui.Views;
2830
using Microsoft.Extensions.Http.Resilience;
2931
using Microsoft.Extensions.Logging;
3032
using Microsoft.Maui.LifecycleEvents;
@@ -65,9 +67,11 @@ public static MauiApp CreateMauiApp()
6567
#endif
6668
.UseMauiCommunityToolkitMarkup()
6769
.UseMauiCommunityToolkitCamera()
68-
.UseMauiCommunityToolkitMediaElement()
69-
70-
.ConfigureMauiHandlers(handlers =>
70+
.UseMauiCommunityToolkitMediaElement(static options =>
71+
{
72+
options.SetDefaultAndroidViewType(AndroidViewType.TextureView);
73+
})
74+
.ConfigureMauiHandlers(static handlers =>
7175
{
7276
#if IOS || MACCATALYST
7377
handlers.AddHandler<CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
</Border.StrokeShape>
3838
<VerticalStackLayout Spacing="6" HeightRequest="250">
3939
<toolkit:MediaElement
40+
AndroidViewType="SurfaceView"
4041
HeightRequest="200"
4142
x:Name="MediaElement"
4243
ShouldAutoPlay="True"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
</Border.StrokeShape>
3838
<VerticalStackLayout Spacing="6" HeightRequest="250">
3939
<toolkit:MediaElement
40+
AndroidViewType="SurfaceView"
4041
HeightRequest="200"
4142
x:Name="MediaElement"
4243
ShouldAutoPlay="True"

samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementMultipleWindowsPage.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using CommunityToolkit.Maui.Core;
12
using CommunityToolkit.Maui.Sample.ViewModels.Views;
23
#if WINDOWS || MACCATALYST
4+
using CommunityToolkit.Maui.Sample.Constants;
35
using CommunityToolkit.Maui.Views;
46
#else
57
using CommunityToolkit.Maui.Markup;
@@ -9,9 +11,7 @@ namespace CommunityToolkit.Maui.Sample.Pages.Views;
911

1012
public partial class MediaElementMultipleWindowsPage : BasePage<MediaElementMultipleWindowsViewModel>
1113
{
12-
const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
1314
#if WINDOWS || MACCATALYST
14-
const string elephantsDreamMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4";
1515
readonly Window secondWindow;
1616
#endif
1717

@@ -22,14 +22,16 @@ public MediaElementMultipleWindowsPage(MediaElementMultipleWindowsViewModel view
2222
{
2323
Content = new MediaElement
2424
{
25-
Source = elephantsDreamMp4Url,
25+
AndroidViewType= AndroidViewType.SurfaceView,
26+
Source = StreamingVideoUrls.ElephantsDream,
2627
ShouldAutoPlay = true
2728
}
2829
});
2930

3031
Content = new MediaElement
3132
{
32-
Source = buckBunnyMp4Url,
33+
AndroidViewType= AndroidViewType.SurfaceView,
34+
Source = StreamingVideoUrls.BuckBunny,
3335
ShouldAutoPlay = true
3436
};
3537
#else

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
55
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
6+
xmlns:constants="clr-namespace:CommunityToolkit.Maui.Sample.Constants"
67
xmlns:viewModels="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Views"
78
xmlns:converters="clr-namespace:CommunityToolkit.Maui.Sample.Converters"
89
x:TypeArguments="viewModels:MediaElementViewModel"
@@ -29,7 +30,7 @@
2930
<toolkit:MediaElement
3031
x:Name="MediaElement"
3132
ShouldAutoPlay="True"
32-
Source="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
33+
Source="{x:Static constants:StreamingVideoUrls.BuckBunny}"
3334
MetadataArtworkUrl="https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm"
3435
MetadataTitle="Big Buck Bunny"
3536
MetadataArtist="Blender Foundation"

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.ComponentModel;
2-
using CommunityToolkit.Maui.Core.Primitives;
3-
using CommunityToolkit.Maui.Extensions;
2+
using CommunityToolkit.Maui.Core;
3+
using CommunityToolkit.Maui.Sample.Constants;
44
using CommunityToolkit.Maui.Sample.ViewModels.Views;
55
using CommunityToolkit.Maui.Views;
66
using Microsoft.Extensions.Logging;
@@ -17,7 +17,6 @@ public partial class MediaElementPage : BasePage<MediaElementViewModel>
1717
const string resetSource = "Reset Source to null";
1818
const string loadMusic = "Load Music";
1919

20-
const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
2120
const string botImageUrl = "https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm";
2221
const string hlsStreamTestUrl = "https://mtoczko.github.io/hls-test-streams/test-gap/playlist.m3u8";
2322
const string hal9000AudioUrl = "https://github.com/prof3ssorSt3v3/media-sample-files/raw/master/hal-9000.mp3";
@@ -170,7 +169,7 @@ async void ChangeSourceClicked(Object sender, EventArgs e)
170169
MediaElement.MetadataArtworkUrl = botImageUrl;
171170
MediaElement.MetadataArtist = "Big Buck Bunny Album";
172171
MediaElement.Source =
173-
MediaSource.FromUri(buckBunnyMp4Url);
172+
MediaSource.FromUri(StreamingVideoUrls.BuckBunny);
174173
return;
175174

176175
case loadHls:
@@ -248,13 +247,13 @@ async void DisplayPopup(object sender, EventArgs e)
248247
MediaElement.Pause();
249248
var popupMediaElement = new MediaElement
250249
{
250+
AndroidViewType = AndroidViewType.SurfaceView,
251251
Source = MediaSource.FromResource("AppleVideo.mp4"),
252252
ShouldAutoPlay = true,
253253
ShouldShowPlaybackControls = true,
254254
};
255-
255+
256256
await this.ShowPopupAsync(popupMediaElement);
257257
popupMediaElement.Stop();
258-
popupMediaElement.Handler?.DisconnectHandler();
259258
}
260259
}

samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3-
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:enableOnBackInvokedCallback="true"
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:enableOnBackInvokedCallback="true" android:hardwareAccelerated="true"
44
android:supportsRtl="true">
55

66
<meta-data android:name="com.google.android.geo.API_KEY" android:value="PASTE-YOUR-API-KEY-HERE" />

samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElement/MediaElementCarouselViewViewModel.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using System.Collections.ObjectModel;
2+
using CommunityToolkit.Maui.Sample.Constants;
3+
24
namespace CommunityToolkit.Maui.Sample.ViewModels.Views;
35

46
public partial class MediaElementCarouselViewViewModel : BaseViewModel
57
{
6-
const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
7-
const string elephantsDreamMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4";
8-
const string sintelMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4";
9-
108
public ObservableCollection<MediaElementDataSource> ItemSource { get; } =
119
[
12-
new(new Uri(buckBunnyMp4Url), "Buck Bunny", 720, 1280),
13-
new(new Uri(elephantsDreamMp4Url), "Elephants Dream", 720, 1280),
14-
new(new Uri(sintelMp4Url), "Sintel", 546, 1280)
10+
new(new Uri(StreamingVideoUrls.BuckBunny), "Buck Bunny", 720, 1280),
11+
new(new Uri(StreamingVideoUrls.ElephantsDream), "Elephants Dream", 720, 1280),
12+
new(new Uri(StreamingVideoUrls.Sintel), "Sintel", 546, 1280)
1513
];
1614
}
1715

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
using System.Collections.ObjectModel;
2+
using CommunityToolkit.Maui.Sample.Constants;
3+
24
namespace CommunityToolkit.Maui.Sample.ViewModels.Views;
35

46
public partial class MediaElementCollectionViewViewModel : BaseViewModel
57
{
6-
const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
7-
const string elephantsDreamMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4";
8-
const string sintelMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4";
9-
108
public ObservableCollection<MediaElementDataSource> ItemSource { get; } =
119
[
12-
new(new Uri(buckBunnyMp4Url), "Buck Bunny", 720, 1280),
13-
new(new Uri(elephantsDreamMp4Url), "Elephants Dream", 720, 1280),
14-
new(new Uri(sintelMp4Url), "Sintel", 546, 1280)
10+
new(new Uri(StreamingVideoUrls.BuckBunny), "Buck Bunny", 720, 1280),
11+
new(new Uri(StreamingVideoUrls.ElephantsDream), "Elephants Dream", 720, 1280),
12+
new(new Uri(StreamingVideoUrls.Sintel), "Sintel", 546, 1280)
1513
];
1614
}

samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElement/MediaElementViewModel.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22

33
public partial class MediaElementViewModel : BaseViewModel
44
{
5-
public MediaElementViewModel()
6-
{
7-
8-
}
95
}

src/CommunityToolkit.Maui.Core/Options.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Options
1212
/// </summary>
1313
/// <param name="value">true if yes or false if you want to implement your own.</param>
1414
/// <remarks>
15-
/// Default value is true.
15+
/// Default value is fasle.
1616
/// </remarks>
1717
public void SetShouldUseStatusBarBehaviorOnAndroidModalPage(bool value) => ShouldUseStatusBarBehaviorOnAndroidModalPage = value;
18-
}
18+
}

src/CommunityToolkit.Maui.MediaElement/AppBuilderExtensions.shared.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Runtime.Versioning;
2+
using CommunityToolkit.Maui.Core;
23
using CommunityToolkit.Maui.Core.Handlers;
34
using CommunityToolkit.Maui.Views;
45

@@ -18,9 +19,14 @@ public static class AppBuilderExtensions
1819
/// Initializes the .NET MAUI Community Toolkit MediaElement Library
1920
/// </summary>
2021
/// <param name="builder"><see cref="MauiAppBuilder"/> generated by <see cref="MauiApp"/>.</param>
22+
/// <param name="options"></param>
2123
/// <returns><see cref="MauiAppBuilder"/> initialized for <see cref="MediaElement"/>.</returns>
22-
public static MauiAppBuilder UseMauiCommunityToolkitMediaElement(this MauiAppBuilder builder)
24+
public static MauiAppBuilder UseMauiCommunityToolkitMediaElement(this MauiAppBuilder builder, Action<MediaElementOptions>? options = null)
2325
{
26+
// Update the default MediaElementOptions for MediaElement if Action is not null
27+
options?.Invoke(new MediaElementOptions(builder));
28+
29+
// Perform Handler configuration
2430
builder.ConfigureMauiHandlers(h =>
2531
{
2632
h.AddHandler<MediaElement, MediaElementHandler>();
@@ -29,6 +35,7 @@ public static MauiAppBuilder UseMauiCommunityToolkitMediaElement(this MauiAppBui
2935
#if ANDROID
3036
builder.Services.AddSingleton<Media.Services.MediaControlsService>();
3137
#endif
38+
3239
return builder;
3340
}
3441
}

src/CommunityToolkit.Maui.MediaElement/AssemblyInfo.shared.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Converters))]
22
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Core))]
3-
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Core.Primitives))]
43
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Core.Handlers))]
54
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Core.Views))]
65
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Views))]

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@
6363
<PackageReference Include="Xamarin.AndroidX.Media3.ExoPlayer.Rtsp" Version="1.5.0" />
6464
<PackageReference Include="Xamarin.AndroidX.Media3.ExoPlayer.Hls" Version="1.5.0" />
6565
<PackageReference Include="Xamarin.AndroidX.Media3.ExoPlayer.Dash" Version="1.5.0" />
66-
<PackageReference Include="Xamarin.AndroidX.Media3.Session" Version="1.5.0" />
66+
<PackageReference Include="Xamarin.AndroidX.Media3.Session" Version="1.5.0" />
67+
68+
<!--include the textureview.xml needed for creating textureview in android-->
69+
<Folder Include="Platforms\Android\Resources\layout\" />
70+
<AndroidResource Include="Platforms\Android\Resources\layout\textureview.xml" />
6771
</ItemGroup>
6872

6973
<ItemGroup>
70-
<PackageReference Include="Microsoft.Maui.Controls" Version="[$(MauiPackageVersion),$(NextMauiPackageVersion))"/>
74+
<PackageReference Include="Microsoft.Maui.Controls" Version="[$(MauiPackageVersion),$(NextMauiPackageVersion))" />
7175
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" Condition=" '$(Configuration)'=='Release' " PrivateAssets="All" />
7276
</ItemGroup>
7377

@@ -76,4 +80,5 @@
7680
<LogicalName>ResourceDictionary.windows.xaml</LogicalName>
7781
</EmbeddedResource>
7882
</ItemGroup>
83+
7984
</Project>

src/CommunityToolkit.Maui.MediaElement/Handlers/MediaElementHandler.android.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ public partial class MediaElementHandler : ViewHandler<MediaElement, MauiMediaEl
1414
/// <param name="mediaElement">The associated <see cref="MediaElement"/> instance.</param>
1515
public static void ShouldLoopPlayback(MediaElementHandler handler, MediaElement mediaElement)
1616
{
17-
handler.mediaManager?.UpdateShouldLoopPlayback();
17+
handler.MediaManager?.UpdateShouldLoopPlayback();
1818
}
1919

2020

2121
protected override MauiMediaElement CreatePlatformView()
2222
{
23-
mediaManager ??= new(MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} cannot be null"),
23+
MediaManager ??= new(MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} cannot be null"),
2424
VirtualView,
2525
Dispatcher.GetForCurrentThread() ?? throw new InvalidOperationException($"{nameof(IDispatcher)} cannot be null"));
2626

27-
var (_, playerView) = mediaManager.CreatePlatformView();
27+
var (_, playerView) = MediaManager.CreatePlatformView(VirtualView.AndroidViewType);
2828
return new(Context, playerView);
2929
}
3030

src/CommunityToolkit.Maui.MediaElement/Handlers/MediaElementHandler.macios.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ protected override MauiMediaElement CreatePlatformView()
1818
throw new InvalidOperationException($"{nameof(MauiContext)} cannot be null");
1919
}
2020

21-
mediaManager ??= new(MauiContext,
21+
MediaManager ??= new(MauiContext,
2222
VirtualView,
2323
Dispatcher.GetForCurrentThread() ?? throw new InvalidOperationException($"{nameof(IDispatcher)} cannot be null"));
2424

25-
(_, playerViewController) = mediaManager.CreatePlatformView();
25+
26+
(_, playerViewController) = MediaManager.CreatePlatformView();
2627

2728
return new(playerViewController, VirtualView);
2829
}

0 commit comments

Comments
 (0)