public TitleDatabase(MainActivity activity)
 {
     list = new List<SongData> ();
     foreach (var ass in activity.Assets.List ("titles")) {
         using (var stream = activity.Assets.Open ("titles/" + ass))
             foreach (var line in new StreamReader (stream).ReadToEnd ().Replace ("\r", "").Split ('\n'))
                 if (!String.IsNullOrEmpty (line) && !line.StartsWith ("//", StringComparison.Ordinal))
                     list.Add (new SongData (line));
     }
 }
        public PlayerView(Player player, TitleDatabase database, MainActivity activity)
        {
            this.player = player;
            this.database = database;
            this.activity = activity;
            this.load_button = activity.FindViewById<Button>(Resource.Id.SelectButton);
            this.play_button = activity.FindViewById<Button>(Resource.Id.PlayButton);
            this.stop_button = activity.FindViewById<Button>(Resource.Id.StopButton);
            this.rescan_button = activity.FindViewById<Button>(Resource.Id.RescanButton);
            this.seekbar = activity.FindViewById<SeekBar>(Resource.Id.SongSeekbar);
            this.title_text_view = activity.FindViewById<TextView>(Resource.Id.SongTitleTextView);
            this.timeline_text_view = activity.FindViewById<TextView>(Resource.Id.TimelineTextView);
            PlayerEnabled = false;

            var ifs = IsolatedStorageFile.GetUserStoreForApplication ();
            if (!ifs.FileExists ("songdirs.txt"))
                load_button.Enabled = false;

            load_button.Click += delegate
            {
                var db = new AlertDialog.Builder (activity);
                db.SetTitle ("Select Music Folder");

                List<string> dirlist = new List<string> ();
                if (ifs.FileExists ("history.txt"))
                    dirlist.Add (from_history_tag);
                using (var sr = new StreamReader (ifs.OpenFile ("songdirs.txt", FileMode.Open)))
                    foreach (var s in sr.ReadToEnd ().Split ('\n'))
                        if (!String.IsNullOrEmpty (s))
                            dirlist.Add (s);
                var dirs = dirlist.ToArray ();

                db.SetItems (dirs, delegate (object o, DialogClickEventArgs e) {
                    string dir = dirs [(int) e.Which];
                    ProcessFileSelectionDialog (dir, delegate (string mus) {
                        player.SelectFile (mus);
                        player.Play ();
                        });
                });
                var dlg = db.Show ();
            };

            play_button.Click += delegate {
                try {
                    if (player.IsPlaying) {
                        player.Pause ();
                    } else {
                        player.Play ();
                    }
                } catch (Exception ex) {
                    play_button.Text = ex.Message;
                }
            };

            stop_button.Click += delegate {
                player.Stop ();
            };

            rescan_button.Click += delegate {
                var db = new AlertDialog.Builder(activity);
                db.SetMessage ("Scan music directories. This operation takes a while.");
                db.SetPositiveButton ("OK", delegate {
                    CreateSongDirectoryList ();
                    load_button.Enabled = true;
                    });
                db.SetCancelable (true);
                db.SetNegativeButton ("Cancel", delegate {});
                db.Show ();
            };
        }
 void Initialize(TitleDatabase database, MainActivity activity)
 {
     this.activity = activity;
     view = new PlayerView (this, database, activity);
     task = new CorePlayer (this);
     headset_status_receiver = new HeadphoneStatusReceiver (this);
 }
 public Player(TitleDatabase database, MainActivity activity)
 {
     Initialize (database, activity);
 }
        public PlayerView(Player player, TitleDatabase database, MainActivity activity)
        {
            this.player             = player;
            this.database           = database;
            this.activity           = activity;
            this.load_button        = activity.FindViewById <Button>(Resource.Id.SelectButton);
            this.play_button        = activity.FindViewById <Button>(Resource.Id.PlayButton);
            this.stop_button        = activity.FindViewById <Button>(Resource.Id.StopButton);
            this.rescan_button      = activity.FindViewById <Button>(Resource.Id.RescanButton);
            this.seekbar            = activity.FindViewById <SeekBar>(Resource.Id.SongSeekbar);
            this.title_text_view    = activity.FindViewById <TextView>(Resource.Id.SongTitleTextView);
            this.timeline_text_view = activity.FindViewById <TextView>(Resource.Id.TimelineTextView);
            PlayerEnabled           = false;

            var ifs = IsolatedStorageFile.GetUserStoreForApplication();

            if (!ifs.FileExists("songdirs.txt"))
            {
                load_button.Enabled = false;
            }

            load_button.Click += delegate
            {
                var db = new AlertDialog.Builder(activity);
                db.SetTitle("Select Music Folder");

                List <string> dirlist = new List <string> ();
                if (ifs.FileExists("history.txt"))
                {
                    dirlist.Add(from_history_tag);
                }
                using (var sr = new StreamReader(ifs.OpenFile("songdirs.txt", FileMode.Open)))
                    foreach (var s in sr.ReadToEnd().Split('\n'))
                    {
                        if (!String.IsNullOrEmpty(s))
                        {
                            dirlist.Add(s);
                        }
                    }
                var dirs = dirlist.ToArray();

                db.SetItems(dirs, delegate(object o, DialogClickEventArgs e) {
                    string dir = dirs [(int)e.Which];
                    ProcessFileSelectionDialog(dir, delegate(string mus) {
                        player.SelectFile(mus);
                        player.Play();
                    });
                });
                var dlg = db.Show();
            };

            play_button.Click += delegate {
                try {
                    if (player.IsPlaying)
                    {
                        player.Pause();
                    }
                    else
                    {
                        player.Play();
                    }
                } catch (Exception ex) {
                    play_button.Text = ex.Message;
                }
            };

            stop_button.Click += delegate {
                player.Stop();
            };

            rescan_button.Click += delegate {
                var db = new AlertDialog.Builder(activity);
                db.SetMessage("Scan music directories. This operation takes a while.");
                db.SetPositiveButton("OK", delegate {
                    CreateSongDirectoryList();
                    load_button.Enabled = true;
                });
                db.SetCancelable(true);
                db.SetNegativeButton("Cancel", delegate {});
                db.Show();
            };
        }
 public Player(TitleDatabase database, MainActivity activity)
 {
     Initialize(database, activity);
 }