Skip to content

Commit

Permalink
iOS: Changed the way the view controllers report that the view is rea…
Browse files Browse the repository at this point in the history
…dy (after ViewDidLoad instead of ViewWillAppear).

Added PlayerPlaylistIndexChangedMessage.

Related to issue #405.
  • Loading branch information
ycastonguay committed Feb 24, 2013
1 parent bc2ffad commit 4c81348
Show file tree
Hide file tree
Showing 25 changed files with 363 additions and 288 deletions.
2 changes: 2 additions & 0 deletions MPfm/MPfm.MVP/Bootstrap/Bootstrapper.cs
Expand Up @@ -22,6 +22,7 @@
using MPfm.MVP.Presenters;
using MPfm.MVP.Helpers;
using MPfm.MVP.Services.Interfaces;
using TinyMessenger;

namespace MPfm.MVP.Bootstrap
{
Expand All @@ -41,6 +42,7 @@ static Bootstrapper()

// Register services
container.Register<IDatabaseFacade>(new DatabaseFacade(ConfigurationHelper.DatabaseFilePath));
container.Register<ITinyMessengerHub, TinyMessengerHub>().AsSingleton();
container.Register<IInitializationService, InitializationService>().AsSingleton();
container.Register<IPlayerService, PlayerService>().AsSingleton();
container.Register<ILibraryService, LibraryService>().AsSingleton();
Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/MPfm.MVP.iOS.csproj
Expand Up @@ -283,5 +283,6 @@
<Compile Include="Presenters\PitchShiftingPresenter.cs" />
<Compile Include="Presenters\Interfaces\IPlayerMetadataPresenter.cs" />
<Compile Include="Presenters\PlayerMetadataPresenter.cs" />
<Compile Include="Messages\PlayerPlaylistIndexChangedMessage.cs" />
</ItemGroup>
</Project>
35 changes: 35 additions & 0 deletions MPfm/MPfm.MVP/Messages/PlayerPlaylistIndexChangedMessage.cs
@@ -0,0 +1,35 @@
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using TinyMessenger;
using MPfm.Player.Events;

namespace MPfm.MVP.Messages
{
/// <summary>
/// Message indicating player playlist index has changed.
/// </summary>
public class PlayerPlaylistIndexChangedMessage : TinyMessageBase
{
public PlayerPlaylistIndexChangedData Data { get; set; }

public PlayerPlaylistIndexChangedMessage(object sender)
: base(sender)
{
}
}
}
12 changes: 10 additions & 2 deletions MPfm/MPfm.MVP/Presenters/PlayerMetadataPresenter.cs
Expand Up @@ -15,10 +15,11 @@
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using MPfm.MVP.Messages;
using MPfm.MVP.Navigation;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Views;
using MPfm.MVP.Services.Interfaces;
using MPfm.MVP.Views;
using TinyMessenger;

namespace MPfm.MVP.Presenters
Expand All @@ -35,13 +36,20 @@ public PlayerMetadataPresenter(ITinyMessengerHub messageHub, IPlayerService play
{
this.playerService = playerService;
this.messageHub = messageHub;

}

private void OnPlaylistIndexChanged(PlayerPlaylistIndexChangedMessage message)
{
View.RefreshAudioFile(message.Data.AudioFileStarted);
}

public override void BindView(IPlayerMetadataView view)
{
// Subscribe to view actions

base.BindView(view);

messageHub.Subscribe<PlayerPlaylistIndexChangedMessage>(OnPlaylistIndexChanged);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions MPfm/MPfm.MVP/Presenters/PlayerPresenter.cs
Expand Up @@ -139,7 +139,7 @@ public void Play()
try
{
playerService.Play();
RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
//RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
timerRefreshSongPosition.Start();
}
catch(Exception ex)
Expand All @@ -157,7 +157,7 @@ public void Play(IEnumerable<AudioFile> audioFiles)
try
{
playerService.Play(audioFiles);
RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
//RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
timerRefreshSongPosition.Start();
}
catch(Exception ex)
Expand All @@ -175,7 +175,7 @@ public void Play(IEnumerable<string> filePaths)
try
{
playerService.Play(filePaths);
RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
//RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
timerRefreshSongPosition.Start();
}
catch(Exception ex)
Expand All @@ -194,7 +194,7 @@ public void Play(IEnumerable<AudioFile> audioFiles, string startAudioFilePath)
try
{
playerService.Play(audioFiles, startAudioFilePath);
RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
//RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
timerRefreshSongPosition.Start();
}
catch(Exception ex)
Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/Services/Interfaces/IPlayerService.cs
Expand Up @@ -29,6 +29,7 @@ namespace MPfm.MVP.Services.Interfaces
public interface IPlayerService
{
bool IsSettingPosition { get; }
bool IsPaused { get; }
PlaylistItem CurrentPlaylistItem { get; }
float Volume { get; }

Expand Down
21 changes: 20 additions & 1 deletion MPfm/MPfm.MVP/Services/PlayerService.cs
Expand Up @@ -24,6 +24,7 @@
using MPfm.Sound.AudioFiles;
using System.Linq;
using MPfm.Sound.Playlists;
using MPfm.Player.Events;

namespace MPfm.MVP.Services
{
Expand All @@ -37,6 +38,7 @@ public class PlayerService : IPlayerService
private PlayerStatusType _status;

public bool IsSettingPosition { get { return _player.IsSettingPosition; } }
public bool IsPaused { get { return _player.IsPaused; } }
public PlaylistItem CurrentPlaylistItem { get { return _player.Playlist.CurrentItem; } }
public float Volume { get { return _player.Volume; } }

Expand All @@ -57,25 +59,34 @@ public void Initialize(Device device, int sampleRate, int bufferSize, int update
{
// Initialize player
_player = new MPfm.Player.Player(device, sampleRate, bufferSize, updatePeriod, true);
_player.OnPlaylistIndexChanged += HandleOnPlaylistIndexChanged;
}

void HandleOnPlaylistIndexChanged(PlayerPlaylistIndexChangedData data)
{
messageHub.PublishAsync(new PlayerPlaylistIndexChangedMessage(this) { Data = data });
}

public void Play()
{
_player.Play();
UpdatePlayerStatus(PlayerStatusType.Playing);
}

public void Play(IEnumerable<AudioFile> audioFiles)
{
_player.Playlist.Clear();
_player.Playlist.AddItems(audioFiles.ToList());
_player.Play();
UpdatePlayerStatus(PlayerStatusType.Playing);
}

public void Play(IEnumerable<string> filePaths)
{
_player.Playlist.Clear();
_player.Playlist.AddItems(filePaths.ToList());
_player.Play();
UpdatePlayerStatus(PlayerStatusType.Playing);
}

public void Play(IEnumerable<AudioFile> audioFiles, string startAudioFilePath)
Expand All @@ -84,27 +95,35 @@ public void Play(IEnumerable<AudioFile> audioFiles, string startAudioFilePath)
_player.Playlist.AddItems(audioFiles.ToList());
_player.Playlist.GoTo(startAudioFilePath);
_player.Play();
UpdatePlayerStatus(PlayerStatusType.Playing);
}

public void Stop()
{
if(_player.IsPlaying)
if (_player.IsPlaying)
{
_player.Stop();
UpdatePlayerStatus(PlayerStatusType.Stopped);
}
}

public void Pause()
{
_player.Pause();
PlayerStatusType statusType = (_player.IsPaused) ? PlayerStatusType.Paused : PlayerStatusType.Playing;
UpdatePlayerStatus(statusType);
}

public void Next()
{
_player.Next();
UpdatePlayerStatus(PlayerStatusType.Playing);
}

public void Previous()
{
_player.Previous();
UpdatePlayerStatus(PlayerStatusType.Playing);
}

public void RepeatType()
Expand Down
2 changes: 2 additions & 0 deletions MPfm/MPfm.MVP/Views/IPlayerMetadataView.cs
Expand Up @@ -16,6 +16,7 @@
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System.Collections.Generic;
using MPfm.Sound.AudioFiles;

namespace MPfm.MVP.Views
{
Expand All @@ -24,5 +25,6 @@ namespace MPfm.MVP.Views
/// </summary>
public interface IPlayerMetadataView : IBaseView
{
void RefreshAudioFile(AudioFile audioFile);
}
}
24 changes: 12 additions & 12 deletions MPfm/MPfm.Player/Player.cs
Expand Up @@ -1155,6 +1155,18 @@ public void Play()
Tracing.Log("Player.Play -- Starting DirectSound playback...");
mixerChannel.Play(false);
}

// Raise audio file finished event (if an event is subscribed)
if (OnPlaylistIndexChanged != null)
{
// Create data
PlayerPlaylistIndexChangedData data = new PlayerPlaylistIndexChangedData();
data.IsPlaybackStopped = false;
data.AudioFileStarted = playlist.CurrentItem.AudioFile;

// Raise event
OnPlaylistIndexChanged(data);
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1393,18 +1405,6 @@ public void GoTo(int index)

// Start playback
Play();

// Raise audio file finished event (if an event is subscribed)
if (OnPlaylistIndexChanged != null)
{
// Create data
PlayerPlaylistIndexChangedData data = new PlayerPlaylistIndexChangedData();
data.IsPlaybackStopped = false;
data.AudioFileStarted = audioFileStarted;

// Raise event
OnPlaylistIndexChanged(data);
}
}

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion MPfm/MPfm.iOS/Classes/Controllers/Base/BaseViewController.cs
Expand Up @@ -48,7 +48,7 @@ public BaseViewController(Action<IBaseView> onViewReady, string nibName, NSBundl
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
OnViewReady(this);
//OnViewReady(this);
}

public override void ViewDidDisappear(bool animated)
Expand All @@ -57,6 +57,12 @@ public override void ViewDidDisappear(bool animated)
OnViewDestroy(this);
}

public override void ViewDidLoad()
{
base.ViewDidLoad();
OnViewReady(this);
}

public static bool UserInterfaceIdiomIsPhone
{
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
Expand Down
7 changes: 7 additions & 0 deletions MPfm/MPfm.iOS/Classes/Controllers/EffectsViewController.cs
Expand Up @@ -31,6 +31,13 @@ public EffectsViewController(Action<IBaseView> onViewReady)
{
}

public override void ViewDidLoad()
{
this.View.BackgroundColor = UIColor.Green;

base.ViewDidLoad();
}

#region IEffectsView implementation

public void UpdateFader(int index, float value)
Expand Down
4 changes: 2 additions & 2 deletions MPfm/MPfm.iOS/Classes/Controllers/LoopsViewController.cs
Expand Up @@ -33,9 +33,9 @@ public LoopsViewController(Action<IBaseView> onViewReady)

public override void ViewDidLoad()
{
base.ViewDidLoad();

this.View.BackgroundColor = UIColor.Green;

base.ViewDidLoad();
}
}
}
4 changes: 2 additions & 2 deletions MPfm/MPfm.iOS/Classes/Controllers/MarkersViewController.cs
Expand Up @@ -33,9 +33,9 @@ public MarkersViewController(Action<IBaseView> onViewReady)

public override void ViewDidLoad()
{
base.ViewDidLoad();

this.View.BackgroundColor = UIColor.Blue;

base.ViewDidLoad();
}
}
}
Expand Up @@ -41,11 +41,11 @@ public MobileLibraryBrowserViewController(Action<IBaseView> onViewReady)

public override void ViewDidLoad()
{
base.ViewDidLoad();

_items = new List<LibraryBrowserEntity>();
tableView.WeakDataSource = this;
tableView.WeakDelegate = this;

base.ViewDidLoad();
}

public override void ViewWillAppear(bool animated)
Expand Down
4 changes: 2 additions & 2 deletions MPfm/MPfm.iOS/Classes/Controllers/MoreViewController.cs
Expand Up @@ -38,11 +38,11 @@ public MoreViewController(Action<IBaseView> onViewReady)

public override void ViewDidLoad()
{
base.ViewDidLoad();

_items = new List<KeyValuePair<MobileOptionsMenuType, string>>();
tableView.WeakDataSource = this;
tableView.WeakDelegate = this;

base.ViewDidLoad();
}

public override void ViewDidDisappear(bool animated)
Expand Down
Expand Up @@ -33,10 +33,9 @@ public PitchShiftingViewController(Action<IBaseView> onViewReady)

public override void ViewDidLoad()
{
base.ViewDidLoad();

this.View.BackgroundColor = UIColor.Brown;
}

base.ViewDidLoad();
}
}
}

0 comments on commit 4c81348

Please sign in to comment.