Ejemplo n.º 1
0
        public void UpdateSong(Song song)
        {
            currentSong = song;
            if (song == null)
            {
                return;
            }
            try {
                nowPlayingInfo = new MPNowPlayingInfo
                {
                    Title      = song?.Name ?? "",
                    Artist     = song?.Artist ?? "",
                    AlbumTitle = song?.Album ?? "",
                    Genre      = song?.Genre ?? "",
                    Artwork    = CreateDefaultArtwork(),
                };
                SetAdditionInfo(song, nowPlayingInfo);

                artwork = null;
                FetchArtwork(song);
                OnSongChanged(song);
                App.RunOnMainThread(() => MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo);
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 2
0
 public void UpdateSong(Song song)
 {
     if (song == null)
     {
         return;
     }
     try
     {
         nowPlayingInfo = new MPNowPlayingInfo
         {
             Title      = song?.Name ?? "",
             Artist     = song?.Artist ?? "",
             AlbumTitle = song?.Album ?? "",
             Genre      = song?.Genre ?? "",
             Artwork    = (new MPMediaItemArtwork(Images.GetDefaultAlbumArt(Images.AlbumArtScreenSize))),
         };
         artwork = null;
         FetchArtwork(song);
         App.RunOnMainThread(() => MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Ejemplo n.º 3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var audioSession = AVAudioSession.SharedInstance();

            audioSession.SetCategory(AVAudioSessionCategory.Playback);
            audioSession.OutputChannelsChanged += (sender, e) => Console.WriteLine("Output channels changed");
            audioSession.SetActive(true);

            // This is not working...
            MPRemoteCommandCenter rcc = MPRemoteCommandCenter.Shared;

            rcc.SeekBackwardCommand.Enabled  = false;
            rcc.SeekForwardCommand.Enabled   = false;
            rcc.NextTrackCommand.Enabled     = false;
            rcc.PreviousTrackCommand.Enabled = false;
            rcc.SkipBackwardCommand.Enabled  = false;
            rcc.SkipForwardCommand.Enabled   = false;

            // You must enable a command so that others can be disabled?
            // See http://stackoverflow.com/a/28925369.
            rcc.PlayCommand.Enabled = true;

            MPNowPlayingInfo nowPlayingInfo = new MPNowPlayingInfo();

            nowPlayingInfo.AlbumTitle = "Vermont";
            nowPlayingInfo.Artist     = "Colchester";
            nowPlayingInfo.Title      = "VPR";
            MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo;

            AVPlayer player = new AVPlayer(audioUrl);

            player.Play();
        }
Ejemplo n.º 4
0
        private void UpdateInfoCenter()
        {
            if (_queue != null && _queue.Count > 0)
            {
                var item = new MPNowPlayingInfo
                {
                    Title               = _queue[_pos].Title,
                    AlbumTitle          = _queue[_pos].Album,
                    Artist              = _queue[_pos].Artist,
                    Genre               = _queue[_pos].Genre,
                    ElapsedPlaybackTime = _player.CurrentTime.Seconds,
                    PlaybackDuration    = _queue[_pos].Duration,
                    PlaybackQueueIndex  = _pos,
                    PlaybackQueueCount  = _queue.Count,
                    PlaybackRate        = _player.Rate
                };
                if (_queue[_pos].Artwork != null)
                {
                    item.Artwork = (MPMediaItemArtwork)_queue[_pos].Artwork;
                }
                MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = item;
            }
            else
            {
                MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = null;
            }

            InvokeOnMainThread(() => {
                UIApplication.SharedApplication.BeginReceivingRemoteControlEvents();
            });
        }
        // Handle control events from lock or control screen
        public void RemoteControlReceived(UIEvent theEvent)
        {
            MPNowPlayingInfo np = new MPNowPlayingInfo();

            if (theEvent.Subtype == UIEventSubtype.RemoteControlPause)
            {
                pause();
            }
            else if (theEvent.Subtype == UIEventSubtype.RemoteControlPlay)
            {
                play();
            }
            else if (theEvent.Subtype == UIEventSubtype.RemoteControlBeginSeekingForward)
            {
                avPlayer.Rate   = SEEK_RATE;
                np.PlaybackRate = SEEK_RATE;
            }
            else if (theEvent.Subtype == UIEventSubtype.RemoteControlEndSeekingForward)
            {
                avPlayer.Rate   = 1.0f;
                np.PlaybackRate = 1.0f;
            }
            else if (theEvent.Subtype == UIEventSubtype.RemoteControlBeginSeekingBackward)
            {
                avPlayer.Rate   = -SEEK_RATE;
                np.PlaybackRate = -SEEK_RATE;
            }
            else if (theEvent.Subtype == UIEventSubtype.RemoteControlEndSeekingBackward)
            {
                avPlayer.Rate   = 1.0f;
                np.PlaybackRate = 1.0f;
            }
            np.ElapsedPlaybackTime = avPlayer.CurrentTime.Seconds;
            SetNowPlayingInfo(currentSong, np);
        }
 // Play song from persistentSongID
 public void playSong(Song song)
 {
     currentSong = song;
     if (song.streamingURL == null)
     {
         MusicQuery  musicQuery = new MusicQuery();
         MPMediaItem mediaItem  = musicQuery.queryForSongWithId(song.songID);
         if (mediaItem != null)
         {
             NSUrl Url = mediaItem.AssetURL;
             item = AVPlayerItem.FromUrl(Url);
             if (item != null)
             {
                 this.avPlayer.ReplaceCurrentItemWithPlayerItem(item);
             }
             MPNowPlayingInfo np = new MPNowPlayingInfo();
             SetNowPlayingInfo(song, np);
             this.play();
         }
     }
     else
     {
         NSUrl nsUrl = NSUrl.FromString(song.streamingURL);
         MyMusicPlayer.myMusicPlayer?.streamingItem?.RemoveObserver(MyMusicPlayer.myMusicPlayer, "status");
         streamingItem = AVPlayerItem.FromUrl(nsUrl);
         streamingItem.AddObserver(this, new NSString("status"), NSKeyValueObservingOptions.New, avPlayer.Handle);
         avPlayer.ReplaceCurrentItemWithPlayerItem(streamingItem);
         streamingItemPaused = false;
         //NSNotificationCenter.DefaultCenter.AddObserver(this, new Selector("playerItemDidReachEnd:"), AVPlayerItem.DidPlayToEndTimeNotification, streamingItem);
     }
 }
        public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
        {
            if (keyPath.ToString() == "status")
            {
                Console.WriteLine("Status Observed Method {0}", avPlayer.Status);
                if (avPlayer.Status == AVPlayerStatus.ReadyToPlay)
                {
                    if (currentSong != null)
                    {
                        currentSong.duration = streamingItem.Duration.Seconds;
                        MPNowPlayingInfo np = new MPNowPlayingInfo();
                        SetNowPlayingInfo(currentSong, np);
                        if (!streamingItemPaused)
                        {
                            this.play();
                        }

                        OnReadyToPlay(new EventArgs());
                    }
                }
                else if (avPlayer.Status == AVPlayerStatus.Failed)
                {
                    Console.WriteLine("Stream Failed");
                }
            }
        }
Ejemplo n.º 8
0
 void SetAdditionInfo(Song song, MPNowPlayingInfo info)
 {
     if (Device.IsIos10)
     {
         nowPlayingInfo.MediaType = Settings.CurrentPlaybackIsVideo ? MPNowPlayingInfoMediaType.Video : MPNowPlayingInfoMediaType.Audio;
     }
 }
Ejemplo n.º 9
0
        public void UpdateElapsed(double position, float playbackSpeed)
        {
            if (mPNowPlayingInfoCenter.NowPlaying == null)
            {
                return;
            }

            if (double.IsNaN(position))
            {
                position = 0;
            }

            var nowPlayingInfo = mPNowPlayingInfoCenter.NowPlaying;
            var newPlayingInfo = new MPNowPlayingInfo()
            {
                Title               = nowPlayingInfo.Title,
                AlbumTitle          = nowPlayingInfo.AlbumTitle,
                Artist              = nowPlayingInfo.Artist,
                ElapsedPlaybackTime = position,
                PlaybackDuration    = nowPlayingInfo.PlaybackDuration,
                PlaybackRate        = playbackSpeed
            };

            mPNowPlayingInfoCenter.NowPlaying = newPlayingInfo;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var audioSession = AVAudioSession.SharedInstance();
            audioSession.SetCategory(AVAudioSessionCategory.Playback);
            audioSession.OutputChannelsChanged += (sender, e) => Console.WriteLine("Output channels changed");
            audioSession.SetActive(true);

            // This is not working...
            MPRemoteCommandCenter rcc = MPRemoteCommandCenter.Shared;
            rcc.SeekBackwardCommand.Enabled = false;
            rcc.SeekForwardCommand.Enabled = false;
            rcc.NextTrackCommand.Enabled = false;
            rcc.PreviousTrackCommand.Enabled = false;
            rcc.SkipBackwardCommand.Enabled = false;
            rcc.SkipForwardCommand.Enabled = false;

            // You must enable a command so that others can be disabled?
            // See http://stackoverflow.com/a/28925369.
            rcc.PlayCommand.Enabled = true;

            MPNowPlayingInfo nowPlayingInfo = new MPNowPlayingInfo();
            nowPlayingInfo.AlbumTitle = "Vermont";
            nowPlayingInfo.Artist = "Colchester";
            nowPlayingInfo.Title = "VPR";
            MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo;

            AVPlayer player = new AVPlayer(audioUrl);
            player.Play();
        }
Ejemplo n.º 11
0
        private MPNowPlayingInfo CreateInfo(StorySong item)
        {
            var newInfo = new MPNowPlayingInfo();

            newInfo.Artwork  = artwork;
            newInfo.Title    = item.Name;
            newInfo.AssetUrl = NSUrl.FromString(item.ImageUri.OriginalString);
            return(newInfo);
        }
Ejemplo n.º 12
0
        private MPNowPlayingInfo CreateNowPlayingInfo(IMediaFile mediaFile)
        {
            var metadata = mediaFile.Metadata;

            if (metadata == null)
            {
                return(null);
            }

            var nowPlayingInfo = new MPNowPlayingInfo
            {
                Title               = metadata.Title,
                AlbumTitle          = metadata.Album,
                AlbumTrackNumber    = metadata.TrackNumber,
                AlbumTrackCount     = metadata.NumTracks,
                Artist              = metadata.Artist,
                Composer            = metadata.Composer,
                DiscNumber          = metadata.DiscNumber,
                Genre               = metadata.Genre,
                ElapsedPlaybackTime = _mediaManager.Position.TotalSeconds,
                PlaybackDuration    = _mediaManager.Duration.TotalSeconds,
                PlaybackQueueIndex  = Queue.Index,
                PlaybackQueueCount  = Queue.Count
            };

            if (_mediaManager.Status == MediaPlayerStatus.Playing)
            {
                nowPlayingInfo.PlaybackRate = 1f;
            }
            else
            {
                nowPlayingInfo.PlaybackRate = 0f;
            }

            if (metadata.AlbumArt != null)
            {
                var cover = metadata.AlbumArt as UIImage;
                if (cover != null)
                {
                    nowPlayingInfo.Artwork = new MPMediaItemArtwork(cover);
                }
            }
            if (!string.IsNullOrEmpty(metadata.AlbumArtUri))
            {
                var cover = UIImage.LoadFromData(NSData.FromUrl(new NSUrl(metadata.AlbumArtUri)));
                if (cover != null)
                {
                    nowPlayingInfo.Artwork = new MPMediaItemArtwork(cover);
                }
            }

            return(nowPlayingInfo);
        }
        private void TrySetNowPlayingInfo(IMediaFile mediaFile)
        {
            if (mediaFile == null)
            {
                return;
            }

            var nowPlaying = CreateNowPlayingInfo(mediaFile);

            if (nowPlaying != null)
            {
                NowPlaying = nowPlaying;
            }
        }
        public void SetUp()
        {
            MPNowPlayingInfoLanguageOption      languageOption      = null;
            MPNowPlayingInfoLanguageOptionGroup languageOptionGroup = null;

            if (v9_0)
            {
                languageOption      = new MPNowPlayingInfoLanguageOption(MPNowPlayingInfoLanguageOptionType.Audible, "en", null, "English", "en");
                languageOptionGroup = new MPNowPlayingInfoLanguageOptionGroup(new MPNowPlayingInfoLanguageOption [] { languageOption }, languageOption, false);
            }
            string file = Path.Combine(NSBundle.MainBundle.ResourcePath, "basn3p08.png");

            using (var img = UIImage.FromFile(file)) {
                NowPlayingInfo = new MPNowPlayingInfo {
                    //MPNowPlayingInfoCenter
                    ElapsedPlaybackTime           = 1.0,
                    PlaybackRate                  = 1.0,
                    DefaultPlaybackRate           = 1.0,
                    PlaybackQueueIndex            = 0,
                    PlaybackQueueCount            = 10,
                    ChapterNumber                 = 1,
                    ChapterCount                  = 10,
                    AvailableLanguageOptions      = v9_0 ? new MPNowPlayingInfoLanguageOptionGroup [] { languageOptionGroup } : null,
                    CurrentLanguageOptions        = v9_0 ? new MPNowPlayingInfoLanguageOption [] { new MPNowPlayingInfoLanguageOption(MPNowPlayingInfoLanguageOptionType.Audible, "en", null, "English", "en") } : null,
                    CollectionIdentifier          = "Collection",
                    ExternalContentIdentifier     = "ExternalContent",
                    ExternalUserProfileIdentifier = "ExternalUserProfile",
                    PlaybackProgress              = 0.5f,
                    MediaType    = MPNowPlayingInfoMediaType.Audio,
                    IsLiveStream = false,
                    AssetUrl     = new NSUrl("https://developer.xamarin.com"),

                    //MPMediaItem
                    AlbumTitle       = "AlbumTitle",
                    AlbumTrackCount  = 13,
                    AlbumTrackNumber = 1,
                    Artist           = "Artist",
                    Artwork          = new MPMediaItemArtwork(img),
                    Composer         = "Composer",
                    DiscCount        = 1,
                    DiscNumber       = 1,
                    Genre            = "Genre",
                    PersistentID     = 1,
                    PlaybackDuration = 100.0,
                    Title            = "Title",
                };
            }
        }
 void SetNowPlayingInfo(Song song, MPNowPlayingInfo np)
 {
     // Pass song info to the lockscreen/control screen
     np.AlbumTitle = song.album;
     np.Artist     = song.artist;
     np.Title      = song.song;
     if (streamingItem != null)
     {
         np.PersistentID = song.songID;
     }
     if (song.artwork != null)
     {
         np.Artwork = song.artwork;
     }
     np.PlaybackDuration = song.duration;
     MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = np;
 }
Ejemplo n.º 16
0
        public override void InitiatePlaybackOfContentItem(MPPlayableContentManager contentManager, NSIndexPath indexPath, Action <NSError> completionHandler)
        {
            try
            {
                DispatchQueue.MainQueue.DispatchAsync(async() =>
                {
                    UIApplication.SharedApplication.EndReceivingRemoteControlEvents();
                    UIApplication.SharedApplication.BeginReceivingRemoteControlEvents();

                    var itemToPlay           = GlobalConstants.PlayLists[indexPath.Row];
                    var NowPlayingInfoCenter = MPNowPlayingInfoCenter.DefaultCenter;

                    MPNowPlayingInfo playingInfo = new MPNowPlayingInfo();
                    playingInfo.Title            = GlobalConstants.PlayLists[indexPath.Row].Name;
                    playingInfo.Artist           = GlobalConstants.PlayLists[indexPath.Row].Editor;
                    playingInfo.PlaybackDuration = GlobalConstants.PlayLists[indexPath.Row].Duration;
                    playingInfo.MediaType        = MPNowPlayingInfoMediaType.Audio;

                    NowPlayingInfoCenter.NowPlaying = playingInfo;

                    var commandCenter = MPRemoteCommandCenter.Shared;
                    commandCenter.PlayCommand.Enabled  = true;
                    commandCenter.PauseCommand.Enabled = true;
                    commandCenter.PauseCommand.AddTarget(PauseButton);

                    var songId          = "11111";
                    string[] identifier = new string[1];
                    identifier[0]       = songId;

                    contentManager = MPPlayableContentManager.Shared;
                    contentManager.NowPlayingIdentifiers = identifier;

                    await CrossMediaManager.Current.Play(GlobalConstants.PlayLists[indexPath.Row].Url);

                    completionHandler(null);

                    UIApplication.SharedApplication.EndReceivingRemoteControlEvents();

                    UIApplication.SharedApplication.BeginReceivingRemoteControlEvents();
                });
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 17
0
        void updateCommandCenterNowPlayingInfo()
        {
            // Define Now Playing Info
            var nowPlayingInfo = new MPNowPlayingInfo
            {
                Title = Asset.Music.DisplayName,
                ElapsedPlaybackTime = PlayerItem.CurrentTime.Seconds,
                PlaybackDuration    = PlayerItem.Asset.Duration.Seconds,
                PlaybackRate        = Player.Rate
            };

            // var image = UIImage.FromBundle ("lockscreen");
            // nowPlayingInfo.Artwork = new MPMediaItemArtwork (image.Size, (arg) => { return image; });

            // Set the metadata
            MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo;
        }
 public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
 {
     Console.WriteLine("Status Observed Method {0}", player.Status);
     if (player.Status == AVPlayerStatus.ReadyToPlay)
     {
         playPauseButton.UserInteractionEnabled = true;
         playPauseButton.TintColor = UIColor.Blue;
         MPNowPlayingInfo np = new MPNowPlayingInfo();
         np.AlbumTitle       = "brad stanfield";
         np.Artist           = "brad stanfield";
         np.Title            = "People Let's Stop the War";
         np.PlaybackDuration = streamingItem.Duration.Seconds;
         MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = np;
         player.Play();
     }
     else if (player.Status == AVPlayerStatus.Failed)
     {
         Title = "Stream Failed";
     }
 }
Ejemplo n.º 19
0
        public void UpdateIsPlaying(float playbackSpeed)
        {
            if (mPNowPlayingInfoCenter.NowPlaying == null)
            {
                return;
            }

            var nowPlayingInfo = mPNowPlayingInfoCenter.NowPlaying;
            var newPlayingInfo = new MPNowPlayingInfo()
            {
                Title               = nowPlayingInfo.Title,
                AlbumTitle          = nowPlayingInfo.AlbumTitle,
                Artist              = nowPlayingInfo.Artist,
                ElapsedPlaybackTime = nowPlayingInfo.ElapsedPlaybackTime,
                PlaybackDuration    = nowPlayingInfo.PlaybackDuration,
                PlaybackRate        = playbackSpeed
            };

            mPNowPlayingInfoCenter.NowPlaying = newPlayingInfo;
        }
Ejemplo n.º 20
0
        private void SetNowPlayingInfo(Track track, Uri coverUri)
        {
            // Moved to ExtendedTabbedRenderer because of a UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
            //UIKit.UIApplication.SharedApplication.BeginReceivingRemoteControlEvents();

            MPNowPlayingInfo np = new MPNowPlayingInfo();

            np.Title      = track.Name;
            np.Artist     = track.Album.Artist.Name;
            np.AlbumTitle = track.Album.Title;
            if (coverUri != null)
            {
                using (var data = NSData.FromUrl(coverUri))
                {
                    if (data != null)
                    {
                        np.Artwork = new MPMediaItemArtwork(UIImage.LoadFromData(data));
                    }
                }
            }

            MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = np;
        }
Ejemplo n.º 21
0
        public void BuildNotification(IMediaItem mediaItem, double position, double duration, float playbackSpeed)
        {
            if (mediaItem == null)
            {
                return;
            }

            if (double.IsNaN(position))
            {
                position = 0;
            }

            var nowPlayingInfo = new MPNowPlayingInfo()
            {
                Title               = mediaItem.Title,
                AlbumTitle          = mediaItem.Album,
                Artist              = mediaItem.Artist,
                ElapsedPlaybackTime = position,
                PlaybackDuration    = duration,
                PlaybackRate        = playbackSpeed
            };

            mPNowPlayingInfoCenter.NowPlaying = nowPlayingInfo;
        }
        public AudioPlayerIOS()
        {
            AVAudioSession audioSession = AVAudioSession.SharedInstance();
            audioSession.SetCategory(AVAudioSessionCategory.Playback);
            audioSession.BeginInterruption += OnAudioSessionBeginInterruption;
            audioSession.EndInterruption += OnAudioSessionEndInterruption;
            audioSession.SetActive(true);

            MPNowPlayingInfo nowPlayingInfo = new MPNowPlayingInfo();
            nowPlayingInfo.AlbumTitle = "California";
            nowPlayingInfo.Artist = "Nevada City";
            nowPlayingInfo.Title = "KVMR";
            MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo;

            // Not clear if these are necessary.  Commenting them out
            // seems to have no effect.
            MPRemoteCommandCenter rcc = MPRemoteCommandCenter.Shared;
            rcc.SeekBackwardCommand.Enabled = false;
            rcc.SeekForwardCommand.Enabled = false;
            rcc.NextTrackCommand.Enabled = false;
            rcc.PreviousTrackCommand.Enabled = false;
            rcc.SkipBackwardCommand.Enabled = false;
            rcc.SkipForwardCommand.Enabled = false;

            // You must enable a command so that others can be disabled?
            // See http://stackoverflow.com/a/28925369.
            rcc.PlayCommand.Enabled = true;
            rcc.PlayCommand.AddTarget(arg =>
                {
                    return MPRemoteCommandHandlerStatus.Success;
                });

            NSNotificationCenter.DefaultCenter.AddObserver(AVPlayerItem.ItemFailedToPlayToEndTimeNotification,
                (notification) =>
                {
                    Console.WriteLine("Received AVPlayerItem.ItemFailedToPlayToEndTimeNotification", notification);
                    Dictionary<string, string> itemFailedProperties = new Dictionary<string, string>();
                    itemFailedProperties.Add("DateTime.UtcNow", DateTime.UtcNow.ToString());
                    itemFailedProperties.Add("AVPlayer.Status", avPlayer?.Status.ToString());
                    itemFailedProperties.Add("AVPlayerItem.Status", avPlayer?.CurrentItem?.Status.ToString());
                    itemFailedProperties.Add("AVPlayer.Error", avPlayer?.Error?.ToString() ?? "isNull");
                    itemFailedProperties.Add("AVPlayerItem.Error",
                        avPlayer?.CurrentItem?.Error?.ToString() ?? "isNull");
                    TelemetryManager.TrackEvent("ItemFailedToPlayToEndTime", itemFailedProperties);
                    Stop();
                    MessagingCenter.Send<LostStreamMessage>(new LostStreamMessage(), "LostStream");
                });
            NSNotificationCenter.DefaultCenter.AddObserver(AVPlayerItem.PlaybackStalledNotification,
                (notification) =>
                {
                    Console.WriteLine("Received AVPlayerItem.PlaybackStalledNotification", notification);
                    Dictionary<string, string> playbackStalledProperties = new Dictionary<string, string>();
                    playbackStalledProperties.Add("DateTime.UtcNow", DateTime.UtcNow.ToString());
                    playbackStalledProperties.Add("AVPlayer.Status", avPlayer?.Status.ToString());
                    playbackStalledProperties.Add("AVPlayerItem.Status", avPlayer?.CurrentItem?.Status.ToString());
                    playbackStalledProperties.Add("AVPlayer.Error", avPlayer?.Error?.ToString() ?? "isNull");
                    playbackStalledProperties.Add("AVPlayerItem.Error",
                        avPlayer?.CurrentItem?.Error?.ToString() ?? "isNull");
                    TelemetryManager.TrackEvent("PlaybackStalled", playbackStalledProperties);
                });
        }
        public override void StopNotifications()
        {
            NowPlaying = null;

            base.StopNotifications();
        }
Ejemplo n.º 24
0
        private void UpdateInfo(MPNowPlayingInfo newInfo)
        {
            var nowPlayingInfoCenter = MPNowPlayingInfoCenter.DefaultCenter;

            nowPlayingInfoCenter.NowPlaying = newInfo;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Must call certain methods in Reachability before ReachabilityChanged
            // will work. See https://forums.xamarin.com/discussion/15291/reachability-changed-event-never-fires
            NetworkStatus networkStatus = Reachability.RemoteHostStatus();
            Reachability.ReachabilityChanged += ReachabilityChanged;

            AVAudioSession audioSession = AVAudioSession.SharedInstance();
            audioSession.SetCategory(AVAudioSessionCategory.Playback);
            audioSession.BeginInterruption += AudioSession_BeginInterruption;
            audioSession.EndInterruption += AudioSession_EndInterruption;
            NSNotificationCenter notificationCenter = NSNotificationCenter.DefaultCenter;
            notificationCenter.AddObserver(this, new ObjCRuntime.Selector("routeChanged:"),
                AVAudioSession.RouteChangeNotification, null);
            audioSession.SetActive(true);

            playPauseButton.TouchUpInside += OnButtonClick;
            btnStatus.TouchUpInside += (sender, e) =>
                Debug.WriteLine("player.Status = {0} and player.Rate = {1}", player?.Status, player?.Rate);
            btnError.TouchUpInside += (sender, e) => Debug.WriteLine("player.Error = {0}", player?.Error);

            MPNowPlayingInfo nowPlayingInfo = new MPNowPlayingInfo();
            nowPlayingInfo.AlbumTitle = "California";
            nowPlayingInfo.Artist = "Nevada City";
            nowPlayingInfo.Title = "KVMR";
            MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo;

            // This is not working...
            MPRemoteCommandCenter rcc = MPRemoteCommandCenter.Shared;
            rcc.SeekBackwardCommand.Enabled = false;
            rcc.SeekForwardCommand.Enabled = false;
            rcc.NextTrackCommand.Enabled = false;
            rcc.PreviousTrackCommand.Enabled = false;
            rcc.SkipBackwardCommand.Enabled = false;
            rcc.SkipForwardCommand.Enabled = false;

            // You must enable a command so that others can be disabled?
            // See http://stackoverflow.com/a/28925369.
            rcc.PlayCommand.Enabled = true;
        }