Skip to content

Commit 71376c8

Browse files
jonmdevne0rrmatrixpictosTheCodeTraveler
authored
Add Android TextureView (#2540)
* test project added * add media element to test project * working implementation * Add Builder Method * comments updated * Remove My Temp Test Project (Unneeded) * removed unneeded "using" * comment update * Update Sample App * Update src/CommunityToolkit.Maui.MediaElement/MediaElement.shared.cs Co-authored-by: Pedro Jesus <[email protected]> * switch to "is not null" rather than != null * add 2nd builder method and alternative xml method * 3 builder options working * remove stopwatch test as done testing * refactored redundancies in UseMauiCommunityToolkitMediaElement * made PlayerView inaccessible to users again * reduce to one version of UseMauiCommunityToolkitMediaElement * Removed second TextureView constructor method * Remove commented code * Move to `Primitives` Folder, Fix Namespaces * Refactor MediaElement `Options`, Update Formatting * Demonstrate `AndroidViewType.SurfaceView` * Use existing ItemGroup * Remove unused code * Add `StreamingVideoUrls` * Remove duplicate string * Pass in `AndroidViewType` * Refactor * Remove unused code * `dotnet format` * Remove redundant MediaElement constructor * Use `SurfaceType` for existing MediaElement pages * Remove embedded videos * Use `.shared.cs` * Update MediaManager.android.cs * Undo changes * `dotnet format` * Use `private set;` * Use SurfaceView * Fix typo * - Fix sample - Fix tizen invalid using statement * Add unit tests for MediaElement default view type Implemented unit tests for `AppBuilderExtensions_MediaElement` and `MediaElementOptions` to validate the setting and retrieval of the default Android view type for media elements. The tests cover various scenarios to ensure expected behavior. * Fix Tizen MediaManager * Fix tests * Add Label to texture view explaining what it can do * Use transparent background * Update MediaElementTextureViewPage.cs * Revert "Fix tests" This reverts commit 5b59f77. * Remove TextureViewPage * Update Unit Tests --------- Co-authored-by: James Crutchley <[email protected]> Co-authored-by: Pedro Jesus <[email protected]> Co-authored-by: Brandon Minnick <[email protected]> Co-authored-by: Brandon Minnick <[email protected]>
1 parent ac6b13a commit 71376c8

File tree

40 files changed

+295
-162
lines changed

40 files changed

+295
-162
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.Models;
@@ -26,6 +27,7 @@
2627
using CommunityToolkit.Maui.Sample.ViewModels.Views;
2728
using CommunityToolkit.Maui.Sample.Views.Popups;
2829
using CommunityToolkit.Maui.Storage;
30+
using CommunityToolkit.Maui.Views;
2931
using Microsoft.Extensions.Http.Resilience;
3032
using Microsoft.Extensions.Logging;
3133
using Microsoft.Maui.LifecycleEvents;
@@ -66,9 +68,11 @@ public static MauiApp CreateMauiApp()
6668
#endif
6769
.UseMauiCommunityToolkitMarkup()
6870
.UseMauiCommunityToolkitCamera()
69-
.UseMauiCommunityToolkitMediaElement()
70-
71-
.ConfigureMauiHandlers(handlers =>
71+
.UseMauiCommunityToolkitMediaElement(static options =>
72+
{
73+
options.SetDefaultAndroidViewType(AndroidViewType.TextureView);
74+
})
75+
.ConfigureMauiHandlers(static handlers =>
7276
{
7377
#if IOS || MACCATALYST
7478
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.ComponentModel;
2-
using CommunityToolkit.Maui.Core.Primitives;
2+
using CommunityToolkit.Maui.Core;
3+
using CommunityToolkit.Maui.Sample.Constants;
34
using CommunityToolkit.Maui.Sample.ViewModels.Views;
45
using CommunityToolkit.Maui.Views;
56
using Microsoft.Extensions.Logging;
@@ -17,7 +18,6 @@ public partial class MediaElementPage : BasePage<MediaElementViewModel>
1718
const string resetSource = "Reset Source to null";
1819
const string loadMusic = "Load Music";
1920

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

176176
case loadHls:
@@ -248,6 +248,7 @@ void DisplayPopup(object sender, EventArgs e)
248248
MediaElement.Pause();
249249
var popupMediaElement = new MediaElement
250250
{
251+
AndroidViewType = AndroidViewType.SurfaceView,
251252
Source = MediaSource.FromResource("AppleVideo.mp4"),
252253
HeightRequest = 600,
253254
WidthRequest = 600,

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

Lines changed: 5 additions & 7 deletions
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
}

0 commit comments

Comments
 (0)