示例#1
0
        static async Task PlayQueueTest()
        {
            Console.WriteLine("Enter username and password (a line for each)");
            Session session = await Spotify.CreateSession(key, cache, settings, userAgent);

            session.MusicDelivered += session_MusicDeliver;
            Error err;

            do
            {
                err = await session.Login(Console.ReadLine(), Console.ReadLine(), false);

                if (err != Error.OK)
                {
                    Console.WriteLine("An error occurred while logging in.\n{0}", err.Message());
                }
            } while (err != Error.OK);

            session.PreferredBitrate = BitRate.Bitrate320k;

            await session.PlaylistContainer;

            while (session.PlaylistContainer.Playlists.Count < 1)
            {
                Console.WriteLine("Found {0} playlists, retrying in 2 sec.", session.PlaylistContainer.Playlists.Count);
                await Task.Delay(TimeSpan.FromSeconds(2));
            }

            AutoResetEvent are = new AutoResetEvent(false);

            PlayQueue queue = new PlayQueue();

            session.EndOfTrack += (s, e) =>
            {
                if (!queue.IsEmpty)
                {
                    var track = queue.Dequeue();
                    session.PlayerUnload();
                    session.PlayerLoad(track);
                    session.PlayerPlay();
                }
                else
                {
                    are.Set();
                }
            };

            var playlist = await session.PlaylistContainer.Playlists[0];

            queue.Seed = playlist.Tracks;
            if (!queue.IsEmpty)
            {
                var track = await queue.Dequeue();

                session.PlayerUnload();
                session.PlayerLoad(track);
                session.PlayerPlay();
                are.WaitOne();
            }
        }
示例#2
0
 static void Main()
 {
     Spotify.CreateSession(key, cache, settings, userAgent);
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new Form1());
 }
示例#3
0
        public SpotifireServer(string password = null)
        {
            if (Instance != null)
            {
                throw new InvalidOperationException("Can't have 2 servers!");
            }
            Instance = this;

            this.password = password;
            this.spotify  = Spotify.CreateSession(Program.applicationKey, Program.cacheLocation, Program.settingsLocation, Program.userAgent);
            this.spotify.SetPrefferedBitrate(sp_bitrate.BITRATE_320k);

            this.spotify.LoginComplete  += new SessionEventHandler(spotify_LoginComplete);
            this.spotify.LogoutComplete += new SessionEventHandler(spotify_LogoutComplete);
            this.spotify.MusicDeliver   += new MusicDeliveryEventHandler(spotify_MusicDeliver);
            this.spotify.EndOfTrack     += new SessionEventHandler(spotify_EndOfTrack);

            this.spotify.StartPlayback += new SessionEventHandler(spotify_StartPlayback);
            this.spotify.StopPlayback  += new SessionEventHandler(spotify_StopPlayback);

            this.playQueue = new LiveQueue <ITrack>();

            this.messageQueue  = new Queue <ClientAction>();
            this.messageLock   = new AutoResetEvent(false);
            this.messageThread = new Thread(new ThreadStart(MessageThread));
            this.messageThread.IsBackground = true;
            this.messageThread.Start();

            player = new BASSPlayer();
        }
示例#4
0
        public SpotifyMusicProvider(ILogger logger, IBufferedPlayer player, ITrackMapper trackMapper, IAlbumMapper albumMapper, ISpotifySettings spotifySettings)
        {
            this.spotifySettings = spotifySettings;
            this.albumMapper     = albumMapper;
            this.trackMapper     = trackMapper;
            this.logger          = logger;
            this.player          = player;

            logger.Debug("Creating Spotify session");
            session = Spotify.CreateSession(spotifySettings.ApplicationKey, "c:\\temp", "c:\\temp", "Spotifire");
            //session.VolumeNormalization = true;
            session.MusicDeliver    += session_MusicDelivered;
            session.EndOfTrack      += session_EndOfTrack;
            session.ConnectionError += session_ConnectionError;
            Login();
        }
示例#5
0
        static async Task Run()
        {
            Console.WriteLine("Enter username and password (a line for each)");
            Session session = await Spotify.CreateSession(key, cache, settings, userAgent);

            session.MusicDelivered += session_MusicDeliver;

            await session.Login(Console.ReadLine(), Console.ReadLine(), false);

            session.PreferredBitrate = BitRate.Bitrate320k;

            TestAwaitLink("spotify:track:0yA1MBQ60SoiYt7xqdS3H1", session);
            TestAwaitLink("spotify:track:3lcP1anKWxdp6IRNF9vGhu", session);
            TestAwaitLink("spotify:track:0cthN0HhrEtp1gIUPhNv2W", session);
            TestAwaitLink("spotify:track:2hlYLICCS20aLk9IfBqMCE", session);

            await session.PlaylistContainer;

            while (session.PlaylistContainer.Playlists.Count < 1)
            {
                Console.WriteLine("Found {0} playlists, retrying in 2 sec.", session.PlaylistContainer.Playlists.Count);
                await Task.Delay(TimeSpan.FromSeconds(2));
            }

            //var toplist = await session.CreateToplistBrowse(ToplistType.Tracks, ToplistRegion.Everywhere, null);
            //var toptrack = await toplist.Tracks[0];
            //Console.WriteLine("Most popular track on spotify: " + toptrack.Name);
            //await session.Play(toptrack);

            //PlayQueue queue = new PlayQueue();

            var playlist = await session.PlaylistContainer.Playlists[0];

            //queue.Seed = playlist.Tracks;
            //while (!queue.IsEmpty)
            //    await session.Play(queue.Dequeue());


            Console.WriteLine("Playing random from " + playlist.Name);
            var track = await playlist.Tracks[new Random().Next(playlist.Tracks.Count)];

            Console.WriteLine("Found track " + track.Name);
            await track.Album;

            var albumBrowse = await track.Album.Browse();                                // test

            var artistBrowse = await track.Artists[0].Browse(ArtistBrowseType.NoAlbums); // test

            var nPlaylist = await session.PlaylistContainer.Playlists.Create(Guid.NewGuid().ToString());

            nPlaylist.Tracks.Add(track);

            var coverId = track.Album.CoverId;
            var image   = await Image.FromId(session, coverId);

            var imageData = image.GetImage();

            imageData.Save("cover.jpg");


            await session.Play(track);

            playlist = await session.Starred;
            Console.WriteLine("Playing random starred track");
            track = await playlist.Tracks[new Random().Next(playlist.Tracks.Count)];
            Console.WriteLine("Found track " + track.Name);
            await session.Play(track);

            Console.WriteLine("Enter song search");
            var search = await session.SearchTracks(Console.ReadLine(), 0, 1);

            if (search.Tracks.Count > 0)
            {
                track = await search.Tracks[0];
                Console.WriteLine("Playing " + track.Name);
                await session.Play(track);
            }
            else
            {
                Console.WriteLine("No matching tracks.");
            }
            await session.Logout();
        }
示例#6
0
 protected override void OnStartup(StartupEventArgs e)
 {
     Spotify.CreateSession(key, cache, settings, userAgent);
     base.OnStartup(e);
 }