public void UnwindToPlayer(UIStoryboardSegue sender)
        {
            var sourceViewController = sender.SourceViewController as FileListViewController;

            if (sourceViewController == null)
            {
                return;
            }

            var mediaItemCollection = sourceViewController.didPickMediaItems;

            if (mediaItemCollection != null)
            {
                collection = mediaItemCollection;
                player.SetQueue(collection);

                var playbackState = player.PlaybackState;
                if (playbackState == MPMusicPlaybackState.Playing)
                {
                    player.Pause();
                }

                player.NowPlayingItem = collection.Items[0];

                playbackState = player.PlaybackState;
                player.Play();
            }
        }
Exemple #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _musicPlayer        = new MPMusicPlayerController();
            _musicPlayer.Volume = volumeSlider.Value;
            _mediaController    = new MPMediaPickerController(MPMediaType.MPMediaTypeMusic);
            _mediaController.AllowsPickingMultipleItems = false;
            _mpDelegate = new MediaPickerDelegate(this);
            _mediaController.Delegate = _mpDelegate;

            volumeSlider.ValueChanged += delegate { _musicPlayer.Volume = volumeSlider.Value; };

            open.Clicked += (o, e) => { this.PresentModalViewController(_mediaController, true); };

            play.Clicked += (o, e) => { _musicPlayer.Play(); };

            pause.Clicked += (o, e) => { _musicPlayer.Pause(); };

            stop.Clicked += (o, e) => { _musicPlayer.Stop(); };
        }
 public override void ViewDidLoad ()
 {
     base.ViewDidLoad ();
     
     _musicPlayer = new MPMusicPlayerController ();
     _musicPlayer.Volume = volumeSlider.Value;
     _mediaController = new MPMediaPickerController (MPMediaType.MPMediaTypeMusic);
     _mediaController.AllowsPickingMultipleItems = false;
     _mpDelegate = new MediaPickerDelegate (this);
     _mediaController.Delegate = _mpDelegate;
     
     volumeSlider.ValueChanged += delegate { _musicPlayer.Volume = volumeSlider.Value; };
     
     open.Clicked += (o, e) => { this.PresentModalViewController (_mediaController, true); };
     
     play.Clicked += (o, e) => { _musicPlayer.Play (); };
     
     pause.Clicked += (o, e) => { _musicPlayer.Pause (); };
     
     stop.Clicked += (o, e) => { _musicPlayer.Stop (); };
 }
Exemple #4
0
 /**	停止時のコールバックメソッド	*/
 public void OnPause()
 {
     System.Diagnostics.Debug.WriteLine("iOS OnPause");
     player.Pause();
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            Console.WriteLine ("PBS VDL");
            this.NavigationController.NavigationBar.TintColor = UIColor.FromRGB (237, 152, 0);
            this.NavigationController.NavigationBar.BarTintColor = UIColor.FromRGB (52, 19, 0);

            float sH = UIScreen.MainScreen.Bounds.Height;
            float sW = UIScreen.MainScreen.Bounds.Width;

            var volumeView = new MPVolumeView(new RectangleF(50,sH - 100,200,50));
            volumeView.ShowsVolumeSlider = true;
            volumeView.ShowsRouteButton = true;
            volumeView.TintColor = UIColor.FromRGB (237, 152, 0);
            View.AddSubview (volumeView);

            var volumeUpView = new UIImageView (new RectangleF (260, sH - 104, 26, 26));
            volumeUpView.Image = UIImage.FromFile("volume_up-26.png");
            View.AddSubview (volumeUpView);

            var volumeDownView = new UIImageView (new RectangleF (20, sH - 104, 26, 26));
            volumeDownView.Image = UIImage.FromFile ("volume_down-26.png");
            View.AddSubview (volumeDownView);

            var pickerView = new UIPickerView (new RectangleF (0, sH - 207, sW, 162)); // heigth must be 162, 180, 216
            pickerView.BackgroundColor = UIColor.FromRGB (52, 19, 0);
            pickerView.TintColor = UIColor.FromRGB (237, 152, 0);
            // not adding to the view yet because this is a multipurpose picker and the addition is done per the purpose with the btn delegate

            positionSld.SetThumbImage (UIImage.FromFile ("position.png"), UIControlState.Normal);
            positionSld.MinValue = 0f;

            // disable all the buttons I don't want enabled when not playing
            playPauseBtn.Enabled = false;
            positionSkipBtn.Enabled = false;
            stopBtn.Enabled = false;
            timerBtn.Enabled = false;
            pickerSetBtn.Hidden = true;
            pickerSetBtn.Enabled = false;
            pickerCnlBtn.Hidden = true;
            pickerCnlBtn.Enabled = false;
            pickerLbl.Hidden = true;

            if (resumeCheck == 1) {
                Console.WriteLine ("F: VDL RPA: " + resumePassAuthor);
                ResumeBook (resumePassTitle, resumePassAuthor);
            }

            _musicPlayer = new MPMusicPlayerController ();
            _mediaController = new MPMediaPickerController (MPMediaType.Music);
            _mediaController.AllowsPickingMultipleItems = false;
            _mpDelegate = new MediaPickerDelegate (this);
            _mediaController.Delegate = _mpDelegate;
            infoScreen = new InfoScreen ();

            addMusicBtn.TouchUpInside += delegate {
                this.PresentViewController(_mediaController, true, null);
            };

            infoBtn.TouchUpInside += delegate {
                this.PresentViewController(infoScreen, true, null);
            };

            positionSkipBtn.Clicked += delegate {
                pickerView.Model = new ThePickerViewModel(0);
                View.AddSubview(pickerView);
                pickerLbl.Text = "Skip To";
                pickerLbl.Hidden = false;
                pickerSetBtn.Enabled = true;
                pickerSetBtn.Hidden = false;
                pickerCnlBtn.Enabled = true;
                pickerCnlBtn.Hidden = false;
            };

            timerBtn.Clicked += (object sender, EventArgs e) => {
                pickerView.Model = new ThePickerViewModel(1);
                View.AddSubview(pickerView);
                pickerLbl.Text = "Sleep Timer";
                pickerLbl.Hidden = false;
                pickerSetBtn.Enabled = true;
                pickerSetBtn.Hidden = false;
                pickerCnlBtn.Enabled = true;
                pickerCnlBtn.Hidden = false;

            };
            pickerSetBtn.TouchUpInside += delegate {
                if (pickerLbl.Text == "Skip To"){
                    int hourValue = pickerView.SelectedRowInComponent(0);
                    int minValue = pickerView.SelectedRowInComponent(1);
                    int secValue = pickerView.SelectedRowInComponent(2);
                    double pickedTimeValue = ((hourValue * 3600) + (minValue * 60) + secValue);
                    int pickedTimeInt = Convert.ToInt32(pickedTimeValue);
                    _musicPlayer.CurrentPlaybackTime = pickedTimeValue;
                    string pickerTimeDisplay = string.Format("{0:#0}:{1:00}:{2:00}",pickedTimeInt/3600,(pickedTimeInt/60)%60,pickedTimeInt%60);
                    currentTimeLbl.Text = pickerTimeDisplay;
                    positionSld.SetValue( (float)(pickedTimeValue), true);

                    pickerView.RemoveFromSuperview();
                    pickerLbl.Hidden = true;
                    pickerSetBtn.Hidden = true;
                    pickerSetBtn.Enabled = false;
                    pickerCnlBtn.Hidden = true;
                    pickerCnlBtn.Enabled = false;
                }
                else if (pickerLbl.Text == "Sleep Timer"){
                    int hourValue = pickerView.SelectedRowInComponent(0);
                    int minValue = pickerView.SelectedRowInComponent(1);
                    double timeToSleep = ((hourValue * 3600) + (minValue * 60));
                    StartSleepTimer(timeToSleep);

                    pickerView.RemoveFromSuperview();
                    pickerLbl.Hidden = true;
                    pickerSetBtn.Hidden = true;
                    pickerSetBtn.Enabled = false;
                    pickerCnlBtn.Hidden = true;
                    pickerCnlBtn.Enabled = false;
                }
                else {
                    pickerView.RemoveFromSuperview();
                    pickerLbl.Hidden = true;
                    pickerSetBtn.Hidden = true;
                    pickerSetBtn.Enabled = false;
                    pickerCnlBtn.Hidden = true;
                    pickerCnlBtn.Enabled = false;
                }
            };

            pickerCnlBtn.TouchUpInside += delegate {
                pickerView.RemoveFromSuperview();
                pickerLbl.Hidden = true;
                pickerSetBtn.Hidden = true;
                pickerSetBtn.Enabled = false;
                pickerCnlBtn.Hidden = true;
                pickerCnlBtn.Enabled = false;
            };

            playPauseBtn.Clicked += (object sender, EventArgs e) => {
                // can I use the playback state for this if statement instead PlayPauseSwitch?
                if (PlayPauseSwitch == null || PlayPauseSwitch == "play"){
                    PlayPauseSwitch = "pause";
                    _musicPlayer.CurrentPlaybackTime = ResumePointVault;
                    Console.WriteLine("playcurrentspot: {0}", _musicPlayer.CurrentPlaybackTime);
                    _musicPlayer.Play();
                    stopBtn.Enabled = true;
                    timerBtn.Enabled = true;
                    double fileLengthRaw = _musicPlayer.NowPlayingItem.PlaybackDuration;
                    StartTimer();
                    _musicPlayer.BeginGeneratingPlaybackNotifications();
                    Console.WriteLine("enabled notifications"); // debugging

                }
                else{
                    PlayPauseSwitch = "play";
                    ResumePointVault = _musicPlayer.CurrentPlaybackTime;
                    _musicPlayer.Pause();
                    refreshTimer.Invalidate();
                }
            };

            positionSld.ValueChanged += delegate {
                _musicPlayer.CurrentPlaybackTime = positionSld.Value;
            };

            stopBtn.Clicked += (object sender, EventArgs e) => {
                Stopper();
            };

            //Lambda Style notfication substription
            notification = MPMusicPlayerController.Notifications.ObservePlaybackStateDidChange ((sender, args) => {
                string val = args.Notification.UserInfo ["MPMusicPlayerControllerPlaybackStateKey"].ToString ();
                Console.WriteLine ("Notification: {0}", args.Notification.UserInfo ["MPMusicPlayerControllerPlaybackStateKey"]);
                PlayPauseImage (val);
            });
        }