Skip to content

Commit

Permalink
iOS: Added position refresh
Browse files Browse the repository at this point in the history
iOS: Added disposing of player in AppDelegate.WillTerminate... it was crashing the whole OS every time the app was exiting... :S

Related to issue #405.

git-svn-id: http://hamster-svn/svn/repos/base@674 765c1f7c-9fb8-954f-9ff8-dd0915cb3117
  • Loading branch information
animal committed Jan 15, 2013
1 parent fc71aee commit 1c4ec97
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 30 deletions.
2 changes: 1 addition & 1 deletion MPfm/branches/current/MPfm.Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Player : MPfm.Player.IPlayer
/// to be static.
/// http://docs.xamarin.com/ios/guides/advanced_topics/limitations
/// </summary>
internal static Player CurrentPlayer = null;
public static Player CurrentPlayer = null;
private System.Timers.Timer timerPlayer = null;
private Channel streamChannel = null;

Expand Down
10 changes: 10 additions & 0 deletions MPfm/branches/current/MPfm.iOS/Classes/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options)

return true;
}

public override void WillTerminate(UIApplication application)
{
// Clean up player
if (MPfm.Player.Player.CurrentPlayer.IsPlaying)
{
MPfm.Player.Player.CurrentPlayer.Stop();
}
MPfm.Player.Player.CurrentPlayer.Dispose();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
using MPfm.Sound.BassNetWrapper;
using MPfm.Sound.BassWrapper;
using System.IO;
using System.Timers;

namespace MPfm.iOS
{
public partial class MPfm_iOSViewController : UIViewController
{
private IPlayer player;
private Timer timer;

static bool UserInterfaceIdiomIsPhone {
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
Expand All @@ -35,6 +37,21 @@ public override void ViewDidLoad ()
{
base.ViewDidLoad ();

timer = new Timer();
timer.Interval = 100;
timer.Elapsed += (sender, e) => {
InvokeOnMainThread(() => {
try
{
lblPosition.Text = player.GetPosition().ToString();
}
catch
{
lblPosition.Text = "Error";
}
});
};

// Perform any additional setup after loading the view, typically from a nib.
Device device = new Device(){
DriverType = DriverType.DirectSound,
Expand All @@ -49,6 +66,7 @@ public override void ViewDidLoad ()
//filePath = filePath.Replace("/Documents", "");
bool exists = File.Exists(filePath);
player.PlayFiles(new List<string> { filePath, filePath2 });
timer.Start();
}

public override void ViewDidUnload ()
Expand All @@ -72,6 +90,21 @@ public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientat
return true;
}
}

partial void actionPlay(NSObject sender)
{
player.Play();
}

partial void actionPause(NSObject sender)
{
player.Pause();
}

partial void actionStop(NSObject sender)
{
player.Stop();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1c4ec97

Please sign in to comment.