Got WPF version work

This commit is contained in:
Vova
2024-01-18 17:42:44 +02:00
parent df51ee3ad6
commit 10b4146772
64 changed files with 866 additions and 411 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TV_Player"
x:Class="TV_Player.App">
xmlns:local="clr-namespace:TV_Player.MAUI"
x:Class="TV_Player.MAUI.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
+1 -1
View File
@@ -1,4 +1,4 @@
namespace TV_Player
namespace TV_Player.MAUI
{
public partial class App : Application
{
+2 -2
View File
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="TV_Player.AppShell"
x:Class="TV_Player.MAUI.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TV_Player"
xmlns:local="clr-namespace:TV_Player.MAUI"
Shell.FlyoutBehavior="Disabled">
<ShellContent
+1 -1
View File
@@ -1,4 +1,4 @@
namespace TV_Player
namespace TV_Player.MAUI
{
public partial class AppShell : Shell
{
+3 -3
View File
@@ -1,7 +1,7 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TV_Player"
x:Class="TV_Player.MainPage">
xmlns:local="clr-namespace:TV_Player.MAUI"
x:Class="TV_Player.MAUI.MainPage">
<ContentPage.BindingContext>
<local:MainViewModel />
</ContentPage.BindingContext>
@@ -15,7 +15,7 @@
SelectedItem="{Binding SelectedItem}"
SelectionChangedCommand="{Binding ItemSelectedCommand}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="local:GroupInfo">
<DataTemplate x:DataType="local:M3UInfo">
<Label Text="{Binding Name}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
+1 -13
View File
@@ -1,4 +1,4 @@
namespace TV_Player
namespace TV_Player.MAUI
{
public partial class MainPage : ContentPage
{
@@ -6,18 +6,6 @@
{
InitializeComponent();
}
//private void OnCounterClicked(object sender, EventArgs e)
//{
// count++;
// if (count == 1)
// CounterBtn.Text = $"Clicked {count} time";
// else
// CounterBtn.Text = $"Clicked {count} times";
// SemanticScreenReader.Announce(CounterBtn.Text);
//}
}
}
+4 -2
View File
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using CommunityToolkit.Maui;
using Microsoft.Extensions.Logging;
namespace TV_Player
namespace TV_Player.MAUI
{
public static class MauiProgram
{
@@ -9,6 +10,7 @@ namespace TV_Player
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkitMediaElement()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
+44
View File
@@ -0,0 +1,44 @@
using LibVLCSharp.Shared;
namespace TV_Player.MAUI
{
public class MediaViewer : ContentView
{
private LibVLC _libVLC;
private MediaPlayer _mediaPlayer;
public static BindableProperty StreamUrlProperty = BindableProperty.Create(nameof(StreamUrl)
, typeof(string)
, typeof(MediaViewer)
, ""
, defaultBindingMode: BindingMode.TwoWay);
public string StreamUrl
{
get => (string)GetValue(StreamUrlProperty);
set
{
SetValue(StreamUrlProperty, value);
}
}
public MediaViewer()
{
InitializeMediaPlayer();
}
private void InitializeMediaPlayer()
{
_libVLC = new LibVLC();
_mediaPlayer = new MediaPlayer(_libVLC);
// var media = new Media(_libVLC, new Uri("http://ost.da-tv.vip/uPVtzdGJfdG9rZW5dIiwibCI6ImE3MWU3N2ZhIiwicCI6ImE3MWU3N2ZhODM1YjMyMTYiLCJjIjoiNDk3IiwidCI6ImUzNjAwZTEwZmFmMGVhYjhhYWY1YTU2YzRkN2VjZTE5IiwiZCI6IjIzMTQ2IiwiciI6IjIzMDM4IiwibSI6InR2IiwiZHQiOiIwIn0eyJ1IjoiaHR0cDovLzQ1LjkzLjQ2LjI3Ojg4ODcvODM2MS92aWRlby5tM3U4P3Rva2V/video.m3u8"));
//_mediaPlayer.Play();
}
public void Play()
{
var media = new Media(_libVLC, new Uri("http://ost.da-tv.vip/uPVtzdGJfdG9rZW5dIiwibCI6ImE3MWU3N2ZhIiwicCI6ImE3MWU3N2ZhODM1YjMyMTYiLCJjIjoiNDk3IiwidCI6ImUzNjAwZTEwZmFmMGVhYjhhYWY1YTU2YzRkN2VjZTE5IiwiZCI6IjIzMTQ2IiwiciI6IjIzMDM4IiwibSI6InR2IiwiZHQiOiIwIn0eyJ1IjoiaHR0cDovLzQ1LjkzLjQ2LjI3Ojg4ODcvODM2MS92aWRlby5tM3U4P3Rva2V/video.m3u8"));
_mediaPlayer.Play(media);
}
}
}
@@ -1,5 +1,6 @@
using Android.App;
using Android.Runtime;
using TV_Player.MAUI;
namespace TV_Player
{
@@ -1,10 +0,0 @@
using Foundation;
namespace TV_Player
{
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
@@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
@@ -1,16 +0,0 @@
using ObjCRuntime;
using UIKit;
namespace TV_Player
{
public class Program
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
-17
View File
@@ -1,17 +0,0 @@
using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using System;
namespace TV_Player
{
internal class Program : MauiApplication
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
static void Main(string[] args)
{
var app = new Program();
app.Run(args);
}
}
}
@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="maui-application-id-placeholder" version="0.0.0" api-version="7" xmlns="http://tizen.org/ns/packages">
<profile name="common" />
<ui-application appid="maui-application-id-placeholder" exec="TV Player.dll" multiple="false" nodisplay="false" taskmanage="true" type="dotnet" launch_mode="single">
<label>maui-application-title-placeholder</label>
<icon>maui-appicon-placeholder</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
</ui-application>
<shortcut-list />
<privileges>
<privilege>http://tizen.org/privilege/internet</privilege>
</privileges>
<dependencies />
<provides-appdefined-privileges />
</manifest>
+1
View File
@@ -1,4 +1,5 @@
using Microsoft.UI.Xaml;
using TV_Player.MAUI;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
-10
View File
@@ -1,10 +0,0 @@
using Foundation;
namespace TV_Player
{
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
-32
View File
@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
-16
View File
@@ -1,16 +0,0 @@
using ObjCRuntime;
using UIKit;
namespace TV_Player
{
public class Program
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TV_Player.MAUI.PlayerPage"
xmlns:local="clr-namespace:TV_Player.MAUI"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Title="PlayerPage"
Loaded="ContentPage_Loaded">
<StackLayout>
<toolkit:MediaElement x:Name="mediaElement"
ShouldAutoPlay="True"
ShouldShowPlaybackControls="True"
Source="http://ost.da-tv.vip/uPVtzdGJfdG9rZW5dIiwibCI6ImE3MWU3N2ZhIiwicCI6ImE3MWU3N2ZhODM1YjMyMTYiLCJjIjoiNDk3IiwidCI6ImUzNjAwZTEwZmFmMGVhYjhhYWY1YTU2YzRkN2VjZTE5IiwiZCI6IjIzMTQ2IiwiciI6IjIzMDM4IiwibSI6InR2IiwiZHQiOiIwIn0eyJ1IjoiaHR0cDovLzQ1LjkzLjQ2LjI3Ojg4ODcvODM2MS92aWRlby5tM3U4P3Rva2V/video.m3u8"
HeightRequest="300"
WidthRequest="400"
/>
<!--<local:MediaViewer x:Name="libVLCSharpView" WidthRequest="300" HeightRequest="300" HorizontalOptions="CenterAndExpand" StreamUrl="{Binding URLSource,Source={x:Reference MyCustomView}}"/>-->
<Button Text="Play" Command="{Binding PlayCommand}" />
</StackLayout>
</ContentPage>
+14
View File
@@ -0,0 +1,14 @@
namespace TV_Player.MAUI;
public partial class PlayerPage : ContentPage
{
public PlayerPage()
{
this.BindingContext = this;
InitializeComponent();
}
private void ContentPage_Loaded(object sender, EventArgs e)
{
}
}
+26
View File
@@ -0,0 +1,26 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TV_Player.MAUI"
x:Class="TV_Player.MAUI.ProgramPage">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
VerticalOptions="Center">
<CollectionView ItemsSource="{Binding Programs}"
ItemsLayout="VerticalGrid, 5" SelectionMode="Single"
SelectedItem="{Binding SelectedItem}"
SelectionChangedCommand="{Binding ItemSelectedCommand}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="local:M3UInfo">
<VerticalStackLayout>
<Image Source="{Binding Logo}" WidthRequest="50" HeightRequest="50"/>
<Label Text="{Binding Name}" HorizontalTextAlignment="Center"/>
</VerticalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
+10
View File
@@ -0,0 +1,10 @@
namespace TV_Player.MAUI
{
public partial class ProgramPage : ContentPage
{
public ProgramPage()
{
InitializeComponent();
}
}
}
@@ -22,12 +22,9 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>
<ItemGroup>
@@ -49,8 +46,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui.MediaElement" Version="3.0.1" />
<PackageReference Include="LibVLCSharp" Version="3.8.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.20" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
@@ -65,4 +65,25 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Update="ProgramPage.xaml.cs">
<DependentUpon>ProgramPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<MauiXaml Update="PlayerPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="ProgramPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>
<ItemGroup>
<None Update="PlayerPage.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>
</Project>
+1 -2
View File
@@ -1,7 +1,6 @@
namespace TV_Player
namespace TV_Player.MAUI
{
public class GroupInfo
{
public string Name { get; set; }
public int Count { get; set; }
+1 -1
View File
@@ -1,4 +1,4 @@
namespace TV_Player
namespace TV_Player.MAUI
{
public class M3UInfo
{
+2 -2
View File
@@ -1,7 +1,7 @@
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
namespace TV_Player
namespace TV_Player.MAUI
{
public static class M3UParser
{
@@ -89,7 +89,7 @@ namespace TV_Player
GroupTitle = match.Groups["GroupTitle"].Value,
Logo = match.Groups["Logo"].Value,
Name = match.Groups["Name"].Value,
Url = match.Groups["Url"].Value
Url = match.Groups["URL"].Value
};
return true;
}
+12 -2
View File
@@ -1,6 +1,6 @@
using System.Windows.Input;
namespace TV_Player
namespace TV_Player.MAUI
{
public class MainViewModel : ObservableViewModelBase
{
@@ -22,7 +22,17 @@ namespace TV_Player
private void OnItemSelected()
{
var navigation = (INavigation)Application.Current.MainPage.Navigation;
var programPageViewModel = new ProgramViewModel(SelectedItem);
// Create a new SecondPage and set its BindingContext to the ViewModel
var programPage = new ProgramPage
{
BindingContext = programPageViewModel
};
// Navigate to the OtherPage
navigation.PushAsync(programPage);
}
}
}
@@ -1,7 +1,7 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace TV_Player
namespace TV_Player.MAUI
{
public abstract class ObservableViewModelBase : INotifyPropertyChanged
{
+49
View File
@@ -0,0 +1,49 @@
using LibVLCSharp.Shared;
using System.Windows.Input;
namespace TV_Player.MAUI
{
public class PlayerViewModel: ObservableViewModelBase
{
private readonly M3UInfo _currentProgram;
private string _urlSource;
public string URLSource
{
get => _urlSource;
set => SetProperty(ref _urlSource, value);
}
public GroupInfo SelectedItem { get; set; }
public ICommand PlayCommand { get; }
public PlayerViewModel(M3UInfo selectedProgram)
{
_currentProgram = selectedProgram;
//PlayM3U8(_currentProgram.Url);
//_libVLC = new LibVLC();
//_mediaPlayer = new MediaPlayer(new Media(_libVLC, new Uri(_currentProgram.Url)));
//_mediaPlayer.Play();
PlayCommand = new Command(OnPlayButtonClicked);
}
private void OnPlayButtonClicked()
{
PlayM3U8(_currentProgram.Url);
}
private void PlayM3U8(string url)
{
try
{
URLSource = _currentProgram.Url;
}
catch (Exception ex)
{
// Handle exceptions
}
}
}
}
+38
View File
@@ -0,0 +1,38 @@
using System.Windows.Input;
namespace TV_Player.MAUI
{
public class ProgramViewModel : ObservableViewModelBase
{
private List<M3UInfo> _programs;
public List<M3UInfo> Programs
{
get => _programs;
set => SetProperty(ref _programs, value);
}
public M3UInfo SelectedItem { get; set; }
public ICommand ItemSelectedCommand { get; }
public ProgramViewModel(GroupInfo groupInfo)
{
ItemSelectedCommand = new Command(OnItemSelected);
ProgramsData.Instance.AllPrograms.Subscribe(x=>Programs = x.Where(p=>p.GroupTitle== groupInfo.Name).ToList());
}
private void OnItemSelected()
{
var navigation = (INavigation)Application.Current.MainPage.Navigation;
var playerViewModel = new PlayerViewModel(SelectedItem);
// Create a new SecondPage and set its BindingContext to the ViewModel
var playerPage = new PlayerPage
{
BindingContext = playerViewModel
};
// Navigate to the OtherPage
navigation.PushAsync(playerPage);
}
}
}
+4 -4
View File
@@ -1,6 +1,6 @@
using System.Reactive.Subjects;
namespace TV_Player
namespace TV_Player.MAUI
{
public class ProgramsData
{
@@ -14,10 +14,10 @@ namespace TV_Player
}
}
private readonly Subject<List<M3UInfo>> programsSubject = new Subject<List<M3UInfo>>();
private readonly Subject<List<GroupInfo>> groupsSubject = new Subject<List<GroupInfo>>();
private readonly ReplaySubject<List<M3UInfo>> programsSubject = new ReplaySubject<List<M3UInfo>>();
private readonly ReplaySubject<List<GroupInfo>> groupsSubject = new ReplaySubject<List<GroupInfo>>();
public IObservable<List<M3UInfo>> AllPrograms => programsSubject;
public Subject<List<GroupInfo>> GroupsInformation => groupsSubject;
public IObservable<List<GroupInfo>> GroupsInformation => groupsSubject;
private ProgramsData()
{