Example #1
0
        private void InitializeSpotify()
        {
            var scopes = new[]
            {
                SpotifyConstants.SPTAuthStreamingScope,
                SpotifyConstants.SPTAuthPlaylistReadPrivateScope,
                SpotifyConstants.SPTAuthUserLibraryReadScope,
                SpotifyConstants.SPTAuthUserReadPrivateScope
            };

            _auth          = SPTAuth.DefaultInstance;
            _spotifyPlayer = SPTAudioStreamingController.SharedInstance();

            _auth.ClientID        = ClientId;
            _auth.RequestedScopes = scopes;
            _auth.RedirectURL     = _redirectUrl;

            _spotifyPlayer.Delegate = this;

            NSError error = null;

            try
            {
                _spotifyPlayer.StartWithClientId(ClientId, out error);
            }
            catch
            {
                Console.WriteLine(error);
                throw;
            }

            StartAuthenticationFlow();
        }
Example #2
0
        public override void AudioStreamingDidLogin(SPTAudioStreamingController audioStreaming)
        {
            Debug.Write("Logged in successfully!", "stream");

            this.Player.SetVolume(1, (arg0) => { });
            AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback);
            AVAudioSession.SharedInstance().SetActive(true);

            this.service.SomethingChanged();
        }
Example #3
0
        public StreamingDelegate(SpotifyMusicServiceIos service)
        {
            NSNotificationCenter.DefaultCenter.AddObserver(new NSString("sessionUpdated"), (NSNotification obj) =>
            {
                Debug.WriteLine("Got session updated notification", "stream");
                this.service = service;
                var auth     = SPTAuth.DefaultInstance;

                if (this.Player == null)
                {
                    NSError error = null;
                    this.Player   = SPTAudioStreamingController.SharedInstance();

                    Debug.WriteLine("Player is " + this.Player == null ? "Null" : "Not null", "stream");

                    bool success = this.Player.StartWithClientId(auth.ClientID, null, SPOTIFY_CACHE_ENABLED, out error);
                    if (success)
                    {
                        this.Player.Delegate         = this;
                        this.Player.PlaybackDelegate = new StreamingPlaybackDelegate(service);
                        if (SPOTIFY_CACHE_ENABLED)
                        {
                            Debug.WriteLine("Spotify cache is enabled", "stream");
                            this.Player.DiskCache = new SPTDiskCache(1024 * 1024 * 64);
                        }
                        else
                        {
                            Debug.WriteLine("Spotify cache is disabled", "stream");
                        }
                    }
                    else
                    {
                        this.Player = null;
                        Debug.WriteLine("*** Error: " + error.Description, "stream");
                        return;
                    }
                }
                else
                {
                    Debug.WriteLine("Player was already not null", "stream");
                }

                Debug.WriteLine("Trying to login with access token", "stream");
                this.Player.LoginWithAccessToken(auth.Session.AccessToken);

                this.service.SomethingChanged();
            });
        }
Example #4
0
        public override void AudioStreamingDidChangePlaybackStatus(SPTAudioStreamingController audioStreaming, bool isPlaying)
        {
            Debug.WriteLine("Playback changed: " + isPlaying, "playback");

            if (isPlaying)
            {
                // This makes it so we can actually hear audio
                // I hate how long it took to figure this out
                AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback);
                AVAudioSession.SharedInstance().SetActive(true);
            }
            else
            {
                AVAudioSession.SharedInstance().SetActive(false);
            }

            service.SomethingChanged();
        }
Example #5
0
 public override void AudioStreamingDidChangePosition(SPTAudioStreamingController audioStreaming, double position)
 {
     //Debug.WriteLine("Position: " + position);
     service.SomethingChanged();
 }
Example #6
0
 public override void AudioStreamingDidStopPlayingTrack(SPTAudioStreamingController audioStreaming, string trackUri)
 {
     Debug.WriteLine("Track ended: " + trackUri, "playback");
     service.SomethingChanged();
     service.SongEnds(trackUri);
 }
Example #7
0
 public override void AudioStreamingDidReceiveMessage(SPTAudioStreamingController audioStreaming, string message)
 {
     Debug.WriteLine("Message: " + message, "stream");
 }
Example #8
0
 public override void AudioStreamingDidReceiveError(SPTAudioStreamingController audioStreaming, NSError error)
 {
     Debug.WriteLine("*** Error: " + error.Description, "stream");
 }
Example #9
0
 public override void AudioStreamingDidLogout(SPTAudioStreamingController audioStreaming)
 {
     this.service.SomethingChanged();
 }