dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.72k forks source link

[Enhancement] TV Apps #2974

Open flimtix opened 2 years ago

flimtix commented 2 years ago

Summary

So far, as far as I know, there is no way to create a TV app using C#. That's why it would be fantastic if you could create such an application using MAUI.

API Changes

This change would mean that MAUI would support Android TV and Apple TV as platforms. These would both be two new territories. The apps should be loaded onto a TV for testing via remote or displayed as an emulator. The control via remote control would have to be added. In addition, a specific package for making platform-dependent changes would have to be included for these platforms.

New targeting platforms

Intended Use Case

If these platforms were available, I would use them to create a TV app that works the same on all devices. You could finally enter this market with C#. TV apps are becoming more and more requested and is a market that has not yet been saturated.

RenatoCaenaro commented 2 years ago

any news about this?

Eilon commented 2 years ago

@Redth - should TV-related issues all be moved to Future?

Redth commented 2 years ago

Yes, we have no current plans to support TV platforms.

sturlath commented 2 years ago

So this will not be pulled from Xamarin to Maui https://docs.microsoft.com/en-us/xamarin/ios/tvos/get-started/hello-tvos ?

MattBDev commented 1 year ago

It's unfortunate that MAUI doesn't support UWP because I would consider XBox apps as "TV apps".

JohnHDev commented 1 year ago

So this will not be pulled from Xamarin to Maui https://docs.microsoft.com/en-us/xamarin/ios/tvos/get-started/hello-tvos ?

Xamarin Forms never supported Apple TV, but Xamarin did and .NET 6 does with the tvOS project type. The way tvOS is implemented imo really doesn't lend itself to Maui at all, it would need to be a subset of the XAML layout controls as it works very differently to iOS.

andrensairr commented 1 year ago

I appreciate the MAUI team may not be ready to support TV, but given the intention to withdraw support for Xamarin and that current advice is to migrate Xamarin projects to .NET 6 (see this), can we see some clarification on Microsoft's position on supporting TV apps in MAUI or Xamarin? Obviously we could try to maintain a legacy project indefinitely, but would set out to do that on a brand new project? Because I for one would like to start one and it's quickly looking like .NET will offer me no reasonable place to start.

michalss commented 1 year ago

Is ATV gonna be supported pls ?

JohnHDev commented 1 year ago

To answer the original question, yes you can create tv apps in c#, I did it with Xamarin for tvOS. The equivalent now is .net 6+, not Maui.

michalss commented 1 year ago

To answer the original question, yes you can create tv apps in c#, I did it with Xamarin for tvOS. The equivalent now is .net 6+, not Maui.

I know that but why i would use a dead technology if Maui is here, simple copy it from Xamarin would do it... Dont get this approach from MS, its stupid... :(

JohnHDev commented 1 year ago

To answer the original question, yes you can create tv apps in c#, I did it with Xamarin for tvOS. The equivalent now is .net 6+, not Maui.

I know that but why i would use a dead technology if Maui is here, simple copy it from Xamarin would do it... Dont get this approach from MS, its stupid... :(

Xamarin isn't moving to .NET Maui, Xamarin is moving to .NET 6, 7, 8 etc. Xamarin Forms is moving to .NET Maui. Xamarin and Xamarin Forms are different things.

You need to understand the technology and what the migration is. Xamarin iOS is being replaced with .net for iOS, Xamarin tvOS is becoming .net for tvOS etc. Xamarin Forms is becoming .NET Maui. Xamarin Forms has never supported tvOS.

bingmapsts commented 6 months ago

I was able create an Android TV app with disabled AOT and trimming.

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = false, Exported = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
[IntentFilter([Intent.ActionMain], Categories = [Intent.CategoryLauncher, Intent.CategoryLeanbackLauncher])]
anton-dot commented 4 months ago

@bingmapsts can you plz provide a sample proj?

Kaaybi commented 4 months ago

I've personally been able to install and launch my own MAUI android application on an android TV without doing any specific tweaking but it is not usable with a remote for now. I'll try to make some more tests in the near future and report some feedback in this issue.

retepz commented 2 months ago

I've personally been able to install and launch my own MAUI android application on an android TV without doing any specific tweaking but it is not usable with a remote for now. I'll try to make some more tests in the near future and report some feedback in this issue.

I ended up manually handling the remote button presses from my android tv. Code is perhaps hacky but seems to work.

Override the collectionviewhandler:

    private static readonly Keycode[] _handledCodes = new[]
    {
        Keycode.DpadUp,
        Keycode.DpadDown,
        Keycode.DpadCenter,
        Keycode.ButtonSelect
    };

        Microsoft.Maui.Controls.Handlers.Items.CollectionViewHandler.Mapper.ModifyMapping(
        nameof(PlatformView),
        (handler, view, args) =>
        {
            if (Application.Current.MainPage is not NavigationPage navPage)
            {
                return;
            }

            var viewModel = navPage.CurrentPage.BindingContext;

            if (viewModel == null)
            {
                return;
            }

            handler.PlatformView.UnhandledKeyEvent += Handle(viewModel);
        });

     // This is only a type "object" to genericize from my original code.        
    private static System.EventHandler<PlatformView.UnhandledKeyEventEventArgs> Handle(object viewModel)
    {
        return (object sender, PlatformView.UnhandledKeyEventEventArgs e) =>
        {
            if (e.Event.Action != KeyEventActions.Down)
            {
                e.Handled = false;
                return;
            }

            var keyCode = e.Event.KeyCode;
            var isHandled = _handledCodes.Contains(keyCode);
            if (!isHandled)
            {
                e.Handled = false;
                return;
            }

            e.Handled = true;

            if (keyCode == Keycode.DpadCenter || keyCode == Keycode.ButtonSelect)
            {
                 viewModel.HandleDpadSelect();
                 return;
            }

            var nextDirectionIsUp = keyCode == Keycode.DpadUp;
            viewModel.HoverOverNext(nextDirectionIsUp);
        };

// Pseudo code for "HoverOverNext"

var nextIndex = nextDirectionIsUp ? _currentIndex - 1 : _currentIndex + 1;
_page.CollectionView.ScrollTo(nextIndex)