Skip to content

Commit

Permalink
添加播放服务,对接播放页。
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjz authored and chenjz committed May 20, 2024
1 parent 7b6f288 commit 77285fb
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 12 deletions.
7 changes: 6 additions & 1 deletion PeachPlayer/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Avalonia.Markup.Xaml;
using Peach.Application.Interfaces;
using Peach.Application.Services;
using PeachPlayer.Services;
using PeachPlayer.Views;
using ReactiveUI;
using Splat;
Expand Down Expand Up @@ -33,7 +34,9 @@ public override void OnFrameworkInitializationCompleted()
{
// DataContext = new MainViewModel()
};
Locator.CurrentMutable.RegisterConstant(new NotificationManager(desktop.MainWindow));
desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnMainWindowClose;

// Locator.CurrentMutable.RegisterConstant(new NotificationManager(desktop.MainWindow));
}
//else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
//{
Expand All @@ -52,6 +55,8 @@ private void ConfigureServiceProvider()
Locator.CurrentMutable.RegisterConstant(new SourceService(), typeof(ISourceService));
Locator.CurrentMutable.RegisterConstant(new SpiderService(), typeof(ISpiderService));

Locator.CurrentMutable.RegisterConstant(new PlayerService(), typeof(IPlayerService));

//Locator.CurrentMutable.RegisterLazySingleton(() => new RuleTestService(), typeof(IRuleTestService));
//Locator.Current.GetService<IRuleTestService>();

Expand Down
Binary file added PeachPlayer/Assets/Images/bg-player.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions PeachPlayer/PeachPlayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<None Remove="Assets\Images\bg-player.jpg" />
<None Remove="Assets\Images\pay\weixinpay.jpg" />
<None Remove="Assets\Images\pay\zhifubaopay.jpg" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions PeachPlayer/Services/IPlayerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Peach.Model.Models;

namespace PeachPlayer.Services
{
public interface IPlayerService
{
void Play(SmallVodModel vod);

}
}
45 changes: 45 additions & 0 deletions PeachPlayer/Services/PlayerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using PeachPlayer.ViewModels;
using PeachPlayer.Views;
using Peach.Model.Models;
using Avalonia.Controls;

namespace PeachPlayer.Services
{
public class PlayerService : IPlayerService
{

//初始化嗅探器

private static VideoPlayView videoPlayView;
private static SmallVodModel vodModel;
private static VideoPlayViewModel videoPlayViewModel;
public PlayerService()
{
videoPlayView = new VideoPlayView();
videoPlayView.Closing += (s, e) =>
{
videoPlayViewModel.Stop();
((Window)s).Hide();
e.Cancel = true;
};
videoPlayViewModel = new VideoPlayViewModel();
videoPlayView.DataContext = videoPlayViewModel;
}

//播放
public void Play(SmallVodModel vod)
{
videoPlayView.Show();
videoPlayView.Activate();
if (videoPlayView.WindowState == WindowState.Minimized)
videoPlayView.WindowState = WindowState.Normal;

if (vodModel != vod)
videoPlayViewModel.Play(vod);

vodModel = vod;
}


}
}
35 changes: 32 additions & 3 deletions PeachPlayer/ViewModels/VideoPlayViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@

using Peach.Application.Interfaces;
using Peach.Model.Models;
using ReactiveUI;
using Splat;


namespace PeachPlayer.ViewModels
{
public class VideoPlayViewModel : ViewModelBase
{
public VideoPlayViewModel() { }
public VideoPlayViewModel(SmallVodModel small)
private VodModel vod=new VodModel();
public VodModel Vod
{
get { return vod; }
set { vod = value; this.RaiseAndSetIfChanged(ref vod, value); }
}

public string VodName => Vod?.vod_name;

public string VodContent => Vod?.vod_content;

public string Type_Remarks => Vod?.vod_remarks;

private IVodInfoService infoService;
public VideoPlayViewModel()
{
infoService = Locator.Current.GetService<IVodInfoService>();
}

public async void Play(SmallVodModel vod)
{
Vod.vod_id = vod.vod_id;
Vod.vod_name = vod.vod_name;
Vod.vod_content = vod.vod_content;
Vod.vod_pic = vod.vod_pic;
Vod.vod_remarks = vod.vod_remarks;

await infoService.DetailsAsync(vod.vod_id);
}

public void Stop()
{

}

}
}
10 changes: 5 additions & 5 deletions PeachPlayer/ViewModels/VideoViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using Peach.Model.Models;
using PeachPlayer.Services;
using ReactiveUI;
using Splat;
using System.Reactive;
using System.Reactive.Linq;

namespace PeachPlayer.ViewModels
{
public class VideoViewModel : ViewModelBase
{

public Interaction<VideoPlayViewModel, SmallVodModel?> ShowDialog { get; }
public ReactiveCommand<Unit, Unit> PlayVodCommand { get; }
private readonly SmallVodModel Vod;

private readonly IPlayerService player;
public VideoViewModel(SmallVodModel vod)
{
Vod = vod;
ShowDialog = new Interaction<VideoPlayViewModel, SmallVodModel?>();
PlayVodCommand = ReactiveCommand.Create(PlayVod);
player = Locator.Current.GetService<IPlayerService>();
}

public string Vid => Vod.vod_id;
Expand All @@ -30,7 +30,7 @@ public async void PlayVod()
{
if (Vod.vod_id != null)
{
var result = await ShowDialog.Handle(new VideoPlayViewModel(Vod));
player.Play(Vod);
}
}

Expand Down
30 changes: 27 additions & 3 deletions PeachPlayer/Views/VideoPlayView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,38 @@
xmlns:ia="clr-namespace:Avalonia.Xaml.Interactions.Core;assembly=Avalonia.Xaml.Interactions"
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaToDecorationsHint="True"
xmlns:vm="using:PeachPlayer.ViewModels"
x:DataType="vm:VideoPlayViewModel"
x:Class="PeachPlayer.Views.VideoPlayView"
Title="VideoPlayView">

<Grid ColumnDefinitions="*,260">
<Border>
<Border.Background>
<ImageBrush Source="/Assets/Images/bg-player.jpg" Stretch="UniformToFill"/>
</Border.Background>
</Border>

<StackPanel Grid.Column="1" Margin="10,0">
<DockPanel Margin="0,15">
<CheckBox Content="追剧" Width="60" Height="30" DockPanel.Dock="Right" VerticalAlignment="Center"/>
<TextBlock FontSize="20" FontWeight="Black" FontStretch="Expanded" Text="{Binding VodName}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center"/>
</DockPanel>
<Expander>
<Expander.Header>
<TextBlock Text="{Binding VodContent}" TextTrimming="CharacterEllipsis" />
</Expander.Header>
<Grid RowDefinitions="*,*" ColumnDefinitions="150,*">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"/>
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"/>
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"/>
</Grid>
</Expander>
<TabControl>
<TabItem Header="线路1"/>
<TabItem Header="线路2"/>
</TabControl>
</StackPanel>

Welcome to Avalonia!
</Grid>
</Window>

0 comments on commit 77285fb

Please sign in to comment.