Skip to content

Commit

Permalink
Merge pull request #231 from myrobotzone/playbackcontroller
Browse files Browse the repository at this point in the history
PlaybackController instance is no longer lost
  • Loading branch information
martijn00 authored Aug 14, 2017
2 parents 5343890 + 0c1e448 commit 42d27a6
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<DependentUpon>UnitTestApp.xaml</DependentUpon>
</Compile>
<Compile Include="Unit\MediaButtonPlaybackControllerTest.cs" />
<Compile Include="Unit\PlaybackControllerProviderMock.cs" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="UnitTestApp.xaml">
Expand Down
21 changes: 13 additions & 8 deletions MediaManager.UWP.Tests/Unit/MediaButtonPlaybackControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void ctor_MediaButtonsAreEnabled()
{
var controlsMock = new Mock<ISystemMediaTransportControlsWrapper>();

new MediaButtonPlaybackController(controlsMock.Object, new Mock<IPlaybackController>().Object);
new MediaButtonPlaybackController(controlsMock.Object, new PlaybackControllerProviderMock().Object);

controlsMock.VerifySet(m => m.IsNextEnabled = true);
controlsMock.VerifySet(m => m.IsPreviousEnabled = true);
Expand All @@ -28,7 +28,7 @@ public void SubscribeToNotifications_SubscribeToMediaButtonEventsIsCalled()
{
var controlsMock = new Mock<ISystemMediaTransportControlsWrapper>();

var controller = new MediaButtonPlaybackController(controlsMock.Object, new Mock<IPlaybackController>().Object);
var controller = new MediaButtonPlaybackController(controlsMock.Object, new PlaybackControllerProviderMock().Object);
controller.SubscribeToNotifications();

controlsMock.Verify(m => m.SubscribeToMediaButtonEvents());
Expand All @@ -39,7 +39,7 @@ public void UnsubscribeFromNotifications_CallsUnsubscribeFromMediaButtonEvents()
{
var controlsMock = new Mock<ISystemMediaTransportControlsWrapper>();

var controller = new MediaButtonPlaybackController(controlsMock.Object, new Mock<IPlaybackController>().Object);
var controller = new MediaButtonPlaybackController(controlsMock.Object, new PlaybackControllerProviderMock().Object);
controller.UnsubscribeFromNotifications();

controlsMock.Verify(m => m.UnsubscribeFromMediaButtonEvents());
Expand All @@ -50,8 +50,9 @@ public void NextButtonPressed_PlayNextIsCalled()
{
var controlsMock = new Mock<ISystemMediaTransportControlsWrapper>();
var playbackControllerMock = new Mock<IPlaybackController>();
var playbackControllerProviderMock = new PlaybackControllerProviderMock().SetupGetPlayBackController(playbackControllerMock.Object);

var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerMock.Object);
var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerProviderMock.Object);
controller.SubscribeToNotifications();

var args = new Mock<ISystemMediaTransportControlsButtonPressedEventArgsWrapper>();
Expand All @@ -66,8 +67,9 @@ public void PreviousButtonPressed_PlayPreviousOrSeekToStartIsCalled()
{
var controlsMock = new Mock<ISystemMediaTransportControlsWrapper>();
var playbackControllerMock = new Mock<IPlaybackController>();
var playbackControllerProviderMock = new PlaybackControllerProviderMock().SetupGetPlayBackController(playbackControllerMock.Object);

var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerMock.Object);
var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerProviderMock.Object);
controller.SubscribeToNotifications();

var args = new Mock<ISystemMediaTransportControlsButtonPressedEventArgsWrapper>();
Expand All @@ -82,8 +84,9 @@ public void PlayButtonPressed_PlayIsCalled()
{
var controlsMock = new Mock<ISystemMediaTransportControlsWrapper>();
var playbackControllerMock = new Mock<IPlaybackController>();
var playbackControllerProviderMock = new PlaybackControllerProviderMock().SetupGetPlayBackController(playbackControllerMock.Object);

var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerMock.Object);
var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerProviderMock.Object);
controller.SubscribeToNotifications();

var args = new Mock<ISystemMediaTransportControlsButtonPressedEventArgsWrapper>();
Expand All @@ -98,8 +101,9 @@ public void PauseButtonPressed_PauseIsCalled()
{
var controlsMock = new Mock<ISystemMediaTransportControlsWrapper>();
var playbackControllerMock = new Mock<IPlaybackController>();
var playbackControllerProviderMock = new PlaybackControllerProviderMock().SetupGetPlayBackController(playbackControllerMock.Object);

var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerMock.Object);
var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerProviderMock.Object);
controller.SubscribeToNotifications();

var args = new Mock<ISystemMediaTransportControlsButtonPressedEventArgsWrapper>();
Expand All @@ -114,8 +118,9 @@ public void StopButtonPressed_StopIsCalled()
{
var controlsMock = new Mock<ISystemMediaTransportControlsWrapper>();
var playbackControllerMock = new Mock<IPlaybackController>();
var playbackControllerProviderMock = new PlaybackControllerProviderMock().SetupGetPlayBackController(playbackControllerMock.Object);

var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerMock.Object);
var controller = new MediaButtonPlaybackController(controlsMock.Object, playbackControllerProviderMock.Object);
controller.SubscribeToNotifications();

var args = new Mock<ISystemMediaTransportControlsButtonPressedEventArgsWrapper>();
Expand Down
14 changes: 14 additions & 0 deletions MediaManager.UWP.Tests/Unit/PlaybackControllerProviderMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Moq;
using Plugin.MediaManager.Abstractions;

namespace Plugin.MediaManager.UWP.Tests.Unit
{
internal class PlaybackControllerProviderMock : Mock<IPlaybackControllerProvider>
{
public PlaybackControllerProviderMock SetupGetPlayBackController(IPlaybackController playbackController)
{
Setup(mock => mock.PlaybackController).Returns(playbackController);
return this;
}
}
}
9 changes: 9 additions & 0 deletions MediaManager.UWP/IPlaybackControllerProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Plugin.MediaManager.Abstractions;

namespace Plugin.MediaManager
{
internal interface IPlaybackControllerProvider
{
IPlaybackController PlaybackController { get; }
}
}
18 changes: 9 additions & 9 deletions MediaManager.UWP/MediaButtonPlaybackController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Plugin.MediaManager
{
public class MediaButtonPlaybackController
internal class MediaButtonPlaybackController
{
private readonly ISystemMediaTransportControlsWrapper _systemMediaTransportControlsWrapper;
private readonly IPlaybackController _playbackController;
private readonly IPlaybackControllerProvider _playbackControllerProvider;

public MediaButtonPlaybackController(ISystemMediaTransportControlsWrapper systemMediaTransportControlsWrapper, IPlaybackController playbackController)
public MediaButtonPlaybackController(ISystemMediaTransportControlsWrapper systemMediaTransportControlsWrapper, IPlaybackControllerProvider playbackControllerProvider)
{
_systemMediaTransportControlsWrapper = systemMediaTransportControlsWrapper;
_playbackController = playbackController;
_playbackControllerProvider = playbackControllerProvider;

_systemMediaTransportControlsWrapper.IsNextEnabled = true;
_systemMediaTransportControlsWrapper.IsPreviousEnabled = true;
Expand All @@ -38,19 +38,19 @@ private async void MediaControls_ButtonPressed(SystemMediaTransportControls send
switch (args.Button)
{
case SystemMediaTransportControlsButton.Next:
await _playbackController.PlayNext();
await _playbackControllerProvider.PlaybackController.PlayNext();
break;
case SystemMediaTransportControlsButton.Previous:
await _playbackController.PlayPreviousOrSeekToStart();
await _playbackControllerProvider.PlaybackController.PlayPreviousOrSeekToStart();
break;
case SystemMediaTransportControlsButton.Play:
await _playbackController.Play();
await _playbackControllerProvider.PlaybackController.Play();
break;
case SystemMediaTransportControlsButton.Pause:
await _playbackController.Pause();
await _playbackControllerProvider.PlaybackController.Pause();
break;
case SystemMediaTransportControlsButton.Stop:
await _playbackController.Stop();
await _playbackControllerProvider.PlaybackController.Stop();
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions MediaManager.UWP/MediaManagerImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Plugin.MediaManager
/// <summary>
/// Implementation for Feature
/// </summary>
public class MediaManagerImplementation : MediaManagerBase
public class MediaManagerImplementation : MediaManagerBase, IPlaybackControllerProvider
{
private IAudioPlayer _audioPlayer;
private IVideoPlayer _videoPlayer;
Expand All @@ -17,7 +17,7 @@ public class MediaManagerImplementation : MediaManagerBase
public MediaManagerImplementation()
{
var systemMediaTransportControlsWrapper = new SystemMediaTransportControlsWrapper(SystemMediaTransportControls.GetForCurrentView());
_mediaButtonPlaybackController = new MediaButtonPlaybackController(systemMediaTransportControlsWrapper, PlaybackController);
_mediaButtonPlaybackController = new MediaButtonPlaybackController(systemMediaTransportControlsWrapper, this);
_mediaButtonPlaybackController.SubscribeToNotifications();
}

Expand Down
4 changes: 4 additions & 0 deletions MediaManager.UWP/Plugin.MediaManager.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<Link>CrossMediaManager.cs</Link>
</Compile>
<Compile Include="AudioPlayerImplementation.cs" />
<Compile Include="IPlaybackControllerProvider.cs" />
<Compile Include="SystemWrappers\ISystemMediaTransportControlsWrapper.cs" />
<Compile Include="SystemWrappers\ISystemMediaTransportControlsButtonPressedEventArgsWrapper.cs" />
<Compile Include="MediaExtractorImplementation.cs" />
Expand All @@ -138,6 +139,9 @@
<Name>Plugin.MediaManager.Abstractions</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down
4 changes: 3 additions & 1 deletion MediaManager.UWP/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]
[assembly: ComVisible(false)]
[assembly: InternalsVisibleTo("Plugin.MediaManager.UWP.Tests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Plugin.MediaManager.SystemWrappers
{
public interface ISystemMediaTransportControlsButtonPressedEventArgsWrapper
internal interface ISystemMediaTransportControlsButtonPressedEventArgsWrapper
{
SystemMediaTransportControlsButton Button { get; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using Windows.Foundation;
using Windows.Foundation;
using Windows.Media;

namespace Plugin.MediaManager.SystemWrappers
{
public interface ISystemMediaTransportControlsWrapper
internal interface ISystemMediaTransportControlsWrapper
{
void SubscribeToMediaButtonEvents();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Windows.Media;
using Windows.Media;

namespace Plugin.MediaManager.SystemWrappers
{
class SystemMediaTransportControlsButtonPressedEventArgsWrapper : ISystemMediaTransportControlsButtonPressedEventArgsWrapper
internal class SystemMediaTransportControlsButtonPressedEventArgsWrapper : ISystemMediaTransportControlsButtonPressedEventArgsWrapper
{
public SystemMediaTransportControlsButton Button { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Plugin.MediaManager.SystemWrappers
{
class SystemMediaTransportControlsWrapper : ISystemMediaTransportControlsWrapper
internal class SystemMediaTransportControlsWrapper : ISystemMediaTransportControlsWrapper
{
private readonly SystemMediaTransportControls _controls;

Expand Down

0 comments on commit 42d27a6

Please sign in to comment.