public NowPlayingData getNowPlaying() { var ret = new NowPlayingData(); try { MPMusicPlayerController player = MPMusicPlayerController.SystemMusicPlayer; if (player.NowPlayingItem != null) { ret.Title = player.NowPlayingItem.Title; ret.Artist = player.NowPlayingItem.Artist; if (player.PlaybackState.Equals(MPMusicPlaybackState.Playing)) { ret.IsPlaying = true; } ret.PlaybackDuration = player.NowPlayingItem.PlaybackDuration; ret.CurrentPlaybackTime = player.CurrentPlaybackTime; ret.Volume = MPMusicPlayerController.SystemMusicPlayer.Volume; var imageBytes = GetTrackImage(player.NowPlayingItem.Artwork); var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Resources); var filePath = Path.Combine(documentsPath, "nowPlaying.png"); ret.ArtWork = GetTrackImageStream(player.NowPlayingItem.Artwork); File.WriteAllBytes(filePath, imageBytes); } } catch (Exception ex) { Console.WriteLine(ex); } return(ret); }
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 (); }; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. toolbar.Translucent = false; pauseButton = new UIBarButtonItem(UIBarButtonSystemItem.Pause, PauseAction); pauseButton.Style = UIBarButtonItemStyle.Plain; pauseButton.TintColor = UIColor.White; player = MPMusicPlayerController.SystemMusicPlayer; player.RepeatMode = MPMusicRepeatMode.All; var notificationCenter = NSNotificationCenter.DefaultCenter; notificationToken1 = notificationCenter.AddObserver(MPMusicPlayerController.NowPlayingItemDidChangeNotification, NowPlayingItemChanged, player); notificationToken2 = notificationCenter.AddObserver(MPMusicPlayerController.PlaybackStateDidChangeNotification, PlaybackStateChanged, player); notificationToken3 = notificationCenter.AddObserver(NSUserDefaults.DidChangeNotification, DefaultsChanged); player.BeginGeneratingPlaybackNotifications(); }
/** コンストラクタ */ public IosAudioPlayer() { /** Player生成 */ player = MPMusicPlayerController.ApplicationMusicPlayer; }
public void ResumeBook(string titleToResume, string resumingAuthor) { string chosenTitle = titleToResume; double aVeryGoodPlaceToStart = 0; dbWorker = new DBWorker (); dbWorker.StartDBWorker (); dbPath = dbWorker.GetPathToDb (); var conn = new SQLiteConnection (dbPath, false); var resumeQuery = conn.Table<SongToSave> ().Where (q => q.BookTitle == chosenTitle); foreach (var result in resumeQuery) { aVeryGoodPlaceToStart = result.PlayPosition - 30; } ResumePointVault = aVeryGoodPlaceToStart; _mediaQuery = new MPMediaQuery (); var value = NSNumber.FromInt32 ((int)MPMediaType.Music); //type of media to return var property = MPMediaItem.MediaTypeProperty; var predicate = MPMediaPropertyPredicate.PredicateWithValue (value, property); _mediaQuery.AddFilterPredicate (predicate); var valueTwo = NSString.FromObject ((String)chosenTitle); var propertyTwo = MPMediaItem.TitleProperty; var predicateTwo = MPMediaPropertyPredicate.PredicateWithValue (valueTwo, propertyTwo); _mediaQuery.AddFilterPredicate (predicateTwo); _musicPlayer = new MPMusicPlayerController (); // volume is dicpercated in ios7 _musicPlayer.SetQueue (_mediaQuery); _musicPlayer.CurrentPlaybackTime = aVeryGoodPlaceToStart; Console.WriteLine ("afterQueSet: {0}", _musicPlayer.CurrentPlaybackTime); positionSkipBtn.Enabled = true; // set the end file length double fileLengthRaw = _musicPlayer.NowPlayingItem.PlaybackDuration; int fileLengthInt = Convert.ToInt32 (fileLengthRaw); string fileLengthDisplay = string.Format ("{0:##}:{1:00}:{2:00}", fileLengthInt / 3600, (fileLengthInt / 60) % 60, fileLengthInt % 60); lengthLbl.Text = fileLengthDisplay; int startingPlaceInt = Convert.ToInt32 (aVeryGoodPlaceToStart); string aVeryGoodPlaceToStartDisplay = string.Format("{0:#0}:{1:00}:{2:00}",startingPlaceInt/3600,(startingPlaceInt/60)%60,startingPlaceInt%60); currentTimeLbl.Text = aVeryGoodPlaceToStartDisplay; Console.WriteLine ("resume point: {0}", aVeryGoodPlaceToStart); // debugging positionSld.MaxValue = (float)(fileLengthRaw); positionSld.SetValue ((float)(aVeryGoodPlaceToStart), true); titleLbl.Text = chosenTitle; artistLbl.Text = resumingAuthor; playPauseBtn.Enabled = true; Console.WriteLine ("ran righ over it"); // debugging Console.WriteLine ("attheresumeend: {0}", _musicPlayer.CurrentPlaybackTime); }
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); }); }
private void OnButtonClicked(object sender, EventArgs e) { MPMusicPlayerController c = new MPMusicPlayerController(); c.SkipToNextItem(); }