-
Notifications
You must be signed in to change notification settings - Fork 431
Add Android TextureView #2540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TheCodeTraveler
merged 60 commits into
CommunityToolkit:main
from
jonmdev:AddAndroidTextureView
May 4, 2025
Merged
Add Android TextureView #2540
Changes from 56 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
c104d70
test project added
jonmdev 7723e5c
add media element to test project
jonmdev 92c2dea
working implementation
jonmdev 18135c5
Add Builder Method
jonmdev e3af126
comments updated
jonmdev 8f3fdf8
Merge branch 'main' into AddAndroidTextureView
ne0rrmatrix d0ec322
Remove My Temp Test Project (Unneeded)
jonmdev d6e2806
Merge branch 'AddAndroidTextureView' of https://github.com/jonmdev/Ma…
jonmdev 6e04927
removed unneeded "using"
jonmdev 55c7b80
comment update
jonmdev 34ace4a
Merge branch 'main' into AddAndroidTextureView
ne0rrmatrix 97d33aa
Update Sample App
ne0rrmatrix fd54261
Update src/CommunityToolkit.Maui.MediaElement/MediaElement.shared.cs
jonmdev 8423996
switch to "is not null" rather than != null
jonmdev 7f298f5
add 2nd builder method and alternative xml method
jonmdev fd785b2
3 builder options working
jonmdev 7e6add8
remove stopwatch test as done testing
jonmdev a8fff6d
refactored redundancies in UseMauiCommunityToolkitMediaElement
jonmdev 86fda83
Merge branch 'main' into AddAndroidTextureView
ne0rrmatrix 6fe89a4
made PlayerView inaccessible to users again
jonmdev 975b739
reduce to one version of UseMauiCommunityToolkitMediaElement
jonmdev 43e222e
Merge branch 'main' into AddAndroidTextureView
ne0rrmatrix a959f9e
Merge branch 'main' into AddAndroidTextureView
ne0rrmatrix 95f6835
Merge branch 'main' into AddAndroidTextureView
ne0rrmatrix b3192b7
Merge branch 'main' into AddAndroidTextureView
TheCodeTraveler eed9323
Merge branch 'main' into AddAndroidTextureView
ne0rrmatrix 41a6b36
Removed second TextureView constructor method
jonmdev 543c271
Remove commented code
TheCodeTraveler ba1b9cc
Move to `Primitives` Folder, Fix Namespaces
TheCodeTraveler eb163dd
Refactor MediaElement `Options`, Update Formatting
TheCodeTraveler a10626e
Demonstrate `AndroidViewType.SurfaceView`
TheCodeTraveler 45b7e23
Use existing ItemGroup
TheCodeTraveler b71ad8b
Remove unused code
TheCodeTraveler da87b7e
Add `StreamingVideoUrls`
TheCodeTraveler d24dde7
Remove duplicate string
TheCodeTraveler efc97ea
Pass in `AndroidViewType`
TheCodeTraveler bb54f87
Refactor
TheCodeTraveler 92d52b1
Remove unused code
TheCodeTraveler ec7e4a1
`dotnet format`
TheCodeTraveler 8fc8666
Remove redundant MediaElement constructor
TheCodeTraveler fa79138
Use `SurfaceType` for existing MediaElement pages
TheCodeTraveler 9183ee2
Remove embedded videos
TheCodeTraveler 0b39d56
Use `.shared.cs`
TheCodeTraveler 2ecd80b
Update MediaManager.android.cs
TheCodeTraveler e67d650
Undo changes
TheCodeTraveler de75055
`dotnet format`
TheCodeTraveler f14a199
Use `private set;`
TheCodeTraveler cdd5bcc
Use SurfaceView
TheCodeTraveler a4c825e
Fix typo
ne0rrmatrix f00c45d
- Fix sample
ne0rrmatrix 8e739c3
Add unit tests for MediaElement default view type
ne0rrmatrix 9052aca
Fix Tizen MediaManager
ne0rrmatrix 5b59f77
Fix tests
ne0rrmatrix 170e221
Add Label to texture view explaining what it can do
ne0rrmatrix 88a01bf
Use transparent background
TheCodeTraveler cc76635
Update MediaElementTextureViewPage.cs
TheCodeTraveler de4d968
Revert "Fix tests"
TheCodeTraveler 3045aec
Merge branch 'main' into AddAndroidTextureView
TheCodeTraveler 889006e
Remove TextureViewPage
TheCodeTraveler 5bf7bff
Update Unit Tests
TheCodeTraveler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
samples/CommunityToolkit.Maui.Sample/Constants/StreamingVideoUrls.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace CommunityToolkit.Maui.Sample.Constants; | ||
|
||
static class StreamingVideoUrls | ||
{ | ||
public const string BuckBunny = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; | ||
public const string ElephantsDream = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"; | ||
public const string Sintel = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementTextureViewPage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using CommunityToolkit.Maui.Core; | ||
using CommunityToolkit.Maui.Markup; | ||
using CommunityToolkit.Maui.Sample.Constants; | ||
using CommunityToolkit.Maui.Sample.ViewModels.Views; | ||
using CommunityToolkit.Maui.Views; | ||
using static CommunityToolkit.Maui.Markup.GridRowsColumns; | ||
|
||
namespace CommunityToolkit.Maui.Sample.Pages.Views; | ||
|
||
public partial class MediaElementTextureViewPage : BasePage<MediaElementTextureViewViewModel> | ||
TheCodeTraveler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
const int mediaElementHeight = 200; | ||
|
||
public MediaElementTextureViewPage(MediaElementTextureViewViewModel viewModel) : base(viewModel) | ||
{ | ||
Content = new Grid | ||
{ | ||
RowSpacing = 24, | ||
RowDefinitions = Rows.Define( | ||
(Row.DescriptionLabel, 64), | ||
(Row.ExplanationLabel, 64), | ||
(Row.Video, mediaElementHeight * 1.75)), // Make the Video Row height slightly less than the height of two MediaElements to ensure overlap | ||
|
||
Children = | ||
{ | ||
new Label() | ||
.Row(Row.DescriptionLabel) | ||
.Text("This page demonstrates two overlaying MediaElements using TextureView on Android. The two videos below have the same height.") | ||
.Font(size: 16), | ||
|
||
new Label() | ||
.Row(Row.ExplanationLabel) | ||
.Text("It is not possible to have overlapping views using SurfaceView on Android; this is only possible using TextureView on Android.") | ||
.Font(size: 16), | ||
|
||
new TextureViewMediaElementInBorder(StreamingVideoUrls.BuckBunny, "https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm") | ||
.Row(Row.Video) | ||
.BackgroundColor(Colors.LightBlue) | ||
.Top(), | ||
|
||
new TextureViewMediaElementInBorder(StreamingVideoUrls.ElephantsDream,"https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm") | ||
.Row(Row.Video) | ||
.BackgroundColor(Colors.LightCoral) | ||
.Bottom(), | ||
} | ||
}; | ||
} | ||
|
||
enum Row { DescriptionLabel, ExplanationLabel, Video } | ||
|
||
sealed class TextureViewMediaElementInBorder : Border | ||
{ | ||
public TextureViewMediaElementInBorder(in string urlSource, in string metaDataArtworkUrl) | ||
{ | ||
Stroke = Colors.Transparent; | ||
StrokeThickness = 0; | ||
Padding = 0; | ||
HeightRequest = mediaElementHeight; | ||
HorizontalOptions = LayoutOptions.Center; | ||
|
||
Content = new MediaElement | ||
{ | ||
AndroidViewType = AndroidViewType.TextureView, | ||
Source = urlSource, | ||
ShouldAutoPlay = true, | ||
MetadataArtist = "Community Toolkit", | ||
MetadataTitle = "Texture View", | ||
MetadataArtworkUrl = metaDataArtworkUrl, | ||
Margin = 0, | ||
BackgroundColor = Colors.Transparent | ||
}.Center(); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
...ityToolkit.Maui.Sample/ViewModels/Views/MediaElement/MediaElementCarouselViewViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
...yToolkit.Maui.Sample/ViewModels/Views/MediaElement/MediaElementCollectionViewViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
using System.Collections.ObjectModel; | ||
using CommunityToolkit.Maui.Sample.Constants; | ||
|
||
namespace CommunityToolkit.Maui.Sample.ViewModels.Views; | ||
|
||
public partial class MediaElementCollectionViewViewModel : BaseViewModel | ||
{ | ||
const string buckBunnyMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; | ||
const string elephantsDreamMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"; | ||
const string sintelMp4Url = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4"; | ||
|
||
public ObservableCollection<MediaElementDataSource> ItemSource { get; } = | ||
[ | ||
new(new Uri(buckBunnyMp4Url), "Buck Bunny", 720, 1280), | ||
new(new Uri(elephantsDreamMp4Url), "Elephants Dream", 720, 1280), | ||
new(new Uri(sintelMp4Url), "Sintel", 546, 1280) | ||
new(new Uri(StreamingVideoUrls.BuckBunny), "Buck Bunny", 720, 1280), | ||
new(new Uri(StreamingVideoUrls.ElephantsDream), "Elephants Dream", 720, 1280), | ||
new(new Uri(StreamingVideoUrls.Sintel), "Sintel", 546, 1280) | ||
]; | ||
} |
5 changes: 5 additions & 0 deletions
5
...nityToolkit.Maui.Sample/ViewModels/Views/MediaElement/MediaElementTextureViewViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace CommunityToolkit.Maui.Sample.ViewModels.Views; | ||
|
||
public partial class MediaElementTextureViewViewModel : BaseViewModel | ||
{ | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,4 @@ | |
|
||
public partial class MediaElementViewModel : BaseViewModel | ||
{ | ||
public MediaElementViewModel() | ||
{ | ||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On
MediaElementPage
, when thePopup
button is clicked, theMediaElement
shown in the popup flickers.Sometimes it shows the video. Sometimes it shows nothing:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a bug unrelated to this PR. If so, please open an Issue.
This also may be a bug on my emulator. If so, please let me know if you are unable to reproduce it on your Android device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As to the flickering specifically that is a known issue with emulator and I cannot replicate it on any physical device on any API.
As to the blank screen I will try to replicate that. I have seen in some cases when navigating to page that video does not load. It looks like that happens with main too. So unrelated to this PR. But further testing is needed to confirm that. I will get that done. User selecting a video from a picker always loads which is weird if initial load is failing. I will have to investigate.