Commit 0c4b88a3 authored by Martin Finkel's avatar Martin Finkel

Add playback on android

parent b584e939
using Android.App;
using Android.Content.PM;
using Android.Content.Res;
using Android.OS;
using ButtonCircle.FormsPlugin.Droid;
using LibVLCSharp.Forms.Shared;
namespace PulseMusic.Droid
{
......@@ -14,7 +16,7 @@ namespace PulseMusic.Droid
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
LibVLCSharpFormsRenderer.Init();
global::Xamarin.Forms.Forms.Init(this, bundle);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(false);
ButtonCircleRenderer.Init();
......
......@@ -54,6 +54,9 @@
<PackageReference Include="SkiaSharp.Views.Forms">
<Version>1.60.2</Version>
</PackageReference>
<PackageReference Include="VideoLAN.LibVLC.Android">
<Version>3.0.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Forms">
<Version>2.4.3.840</Version>
</PackageReference>
......@@ -132,5 +135,10 @@
<ItemGroup>
<AndroidResource Include="Resources\drawable\shuffle.png" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Assets\Imagine Dragons - Radioactive.mp3">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</AndroidAsset>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -4073,6 +4073,9 @@ namespace PulseMusic.Droid
// aapt resource value: 0x7f0a0025
public const int abc_toolbar_collapse_description = 2131361829;
// aapt resource value: 0x7f0a003c
public const int app_name = 2131361852;
// aapt resource value: 0x7f0a0033
public const int appbar_scrolling_view_behavior = 2131361843;
......
......@@ -11,7 +11,9 @@ namespace PulseMusic
{
InitializeComponent();
MainPage = new PlayerView();
DependencyService.Register<PlaybackService>();
MainPage = new PlayerView();
}
protected override void OnStart ()
......
using LibVLCSharp.Shared;
using PulseMusic.ViewModels;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace PulseMusic
{
public class PlaybackService
{
LibVLC _libVLC;
MediaPlayer _mp;
const string SONG_NAME = "Imagine Dragons - Radioactive.mp3";
public PlaybackService()
{
Core.Initialize();
_libVLC = new LibVLC();
_mp = new MediaPlayer(_libVLC);
}
async Task<Stream> SongStream() => await FileSystem.OpenAppPackageFileAsync(SONG_NAME);
public async void Init()
{
_mp.Media = new Media(_libVLC, await SongStream(), ":no-video");
MessagingCenter.Subscribe<PlayerViewModel, bool>(this, MessengerKeys.Play, (vm, play) =>
{
if (play)
_mp.Play();
else _mp.Pause();
});
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LibVLCSharp.Forms" Version="0.1.3" />
<PackageReference Include="Plugins.Forms.ButtonCircle" Version="2.0.3" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="1.60.2" />
<PackageReference Include="Xamarin.Essentials" Version="1.0.0" />
<PackageReference Include="Xamarin.FFImageLoading.Forms" Version="2.4.3.840" />
<PackageReference Include="Xamarin.FFImageLoading.Transformations" Version="2.4.3.840" />
<PackageReference Include="Xamarin.Forms" Version="3.2.0.871581" />
......
......@@ -18,10 +18,12 @@ namespace PulseMusic.ViewModels
private bool _isPlaying;
private double _progress;
private string _icon;
private PlaybackService _playbackService;
public PlayerViewModel()
{
_countdown = new Countdown();
_playbackService = DependencyService.Get<PlaybackService>();
IsPlaying = true;
Icon = "pause";
......@@ -77,6 +79,8 @@ namespace PulseMusic.ViewModels
public override Task LoadAsync()
{
_playbackService.Init();
LoadSong();
_countdown.StartTime = TimeSpan.Zero;
......@@ -88,8 +92,7 @@ namespace PulseMusic.ViewModels
_countdown.Ticked += OnCountdownTicked;
_countdown.Completed += OnCountdownCompleted;
MessagingCenter.Send(MessengerKeys.App, MessengerKeys.Play, IsPlaying);
MessagingCenter.Send(this, MessengerKeys.Play, IsPlaying);
return base.LoadAsync();
}
......@@ -129,7 +132,7 @@ namespace PulseMusic.ViewModels
Progress = 0;
IsPlaying = false;
MessagingCenter.Send(MessengerKeys.App, MessengerKeys.Play, IsPlaying);
MessagingCenter.Send(this, MessengerKeys.Play, IsPlaying);
}
void Play()
......@@ -146,7 +149,7 @@ namespace PulseMusic.ViewModels
Icon = "play";
}
MessagingCenter.Send(MessengerKeys.App, MessengerKeys.Play, IsPlaying);
MessagingCenter.Send(this, MessengerKeys.Play, IsPlaying);
}
void Rewind()
......
......@@ -290,26 +290,26 @@ Global
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.AppStore|iPhone.Build.0 = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Debug|iPhone.Build.0 = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Release|Any CPU.Build.0 = Release|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Release|iPhone.ActiveCfg = Release|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Release|iPhone.Build.0 = Release|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{9A168B62-AE4F-42A5-9960-44DE18D04C31}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Ad-Hoc|Any CPU.ActiveCfg = Ad-Hoc|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Ad-Hoc|iPhoneSimulator
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Ad-Hoc|iPhoneSimulator.Build.0 = Ad-Hoc|iPhoneSimulator
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.AppStore|Any CPU.ActiveCfg = AppStore|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.AppStore|iPhone.ActiveCfg = AppStore|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.AppStore|iPhone.Build.0 = AppStore|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.AppStore|iPhoneSimulator.ActiveCfg = AppStore|iPhoneSimulator
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.AppStore|iPhoneSimulator.Build.0 = AppStore|iPhoneSimulator
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Debug|Any CPU.ActiveCfg = Debug|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Debug|iPhone.ActiveCfg = Debug|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Debug|iPhone.Build.0 = Debug|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Release|Any CPU.ActiveCfg = Release|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Release|iPhone.ActiveCfg = Release|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Release|iPhone.Build.0 = Release|iPhone
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{C9F0F801-61E0-4297-B3AB-32FCA8998395}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment