Exemplo n.º 1
0
        public override void Initialize()
        {
            _callbacks = new NativeSessionCallbacks(this);

            if (!string.IsNullOrEmpty(_options.SettingsLocation))
            {
                Directory.CreateDirectory(_options.SettingsLocation);
            }

            var sessionConfig = new Spotify.SpotifySessionConfig
            {
                ApiVersion = Spotify.SPOTIFY_API_VERSION,
                CacheLocation = _options.CacheLocation,
                SettingsLocation = _options.SettingsLocation,
                UserAgent = _options.UserAgent,
                CompressPlaylists = _options.CompressPlaylists,
                DontSaveMetadataForPlaylists = _options.DontSavePlaylistMetadata,
                InitiallyUnloadPlaylists = _options.InitiallyUnloadPlaylists,
                ApplicationKey = Marshal.AllocHGlobal(_applicationKey.Length),
                ApplicationKeySize = _applicationKey.Length,
                Callbacks = _callbacks.CallbackHandle,
                DeviceID = _options.DeviceID,
                TraceFile = _options.TraceFileLocation
            };

            try
            {
                Marshal.Copy(_applicationKey, 0, sessionConfig.ApplicationKey, _applicationKey.Length);

                lock (Spotify.Mutex)
                {
                    IntPtr sessionPtr;
                    Error res = Spotify.sp_session_create(ref sessionConfig, out sessionPtr);

                    if (res != Error.OK)
                    {
                        throw new Exception(res.GetMessage());
                    }

                    Handle = sessionPtr;
                }
            }
            finally
            {
                if (sessionConfig.ApplicationKey != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(sessionConfig.ApplicationKey);
                    sessionConfig.ApplicationKey = IntPtr.Zero;
                }
            }

            _mainThreadNotification = new AutoResetEvent(false);
            _mainThread = new Thread(MainThreadLoop);
            _mainThread.Name = "MainLoop";
            _mainThread.IsBackground = true;
            _mainThread.Start();

            _eventQueue = new Queue<DelegateInvoker>();

            _eventThread = new Thread(EventThreadLoop);
            _eventThread.Name = "EventLoop";
            _eventThread.IsBackground = true;
            _eventThread.Start();

            AppDomain.CurrentDomain.ProcessExit += OnHostProcessExit;
        }
Exemplo n.º 2
0
        public override void Initialize()
        {
            _callbacks = new NativeSessionCallbacks(this);

            if (!string.IsNullOrEmpty(_options.SettingsLocation))
            {
                Directory.CreateDirectory(_options.SettingsLocation);
            }

            var sessionConfig = new Spotify.SpotifySessionConfig
            {
                ApiVersion                   = Spotify.SPOTIFY_API_VERSION,
                CacheLocation                = _options.CacheLocation,
                SettingsLocation             = _options.SettingsLocation,
                UserAgent                    = _options.UserAgent,
                CompressPlaylists            = _options.CompressPlaylists,
                DontSaveMetadataForPlaylists = _options.DontSavePlaylistMetadata,
                InitiallyUnloadPlaylists     = _options.InitiallyUnloadPlaylists,
                ApplicationKey               = Marshal.AllocHGlobal(_applicationKey.Length),
                ApplicationKeySize           = _applicationKey.Length,
                Callbacks                    = _callbacks.CallbackHandle,
                DeviceID      = _options.DeviceID,
                TraceFile     = _options.TraceFileLocation,
                Proxy         = _options.Proxy,
                ProxyUsername = _options.ProxyUsername,
                ProxyPassword = _options.ProxyPassword
            };

            try
            {
                Marshal.Copy(_applicationKey, 0, sessionConfig.ApplicationKey, _applicationKey.Length);

                lock (Spotify.Mutex)
                {
                    IntPtr sessionPtr;
                    Error  res = Spotify.sp_session_create(ref sessionConfig, out sessionPtr);

                    if (res != Error.OK)
                    {
                        throw new TorshifyException(res.GetMessage(), res);
                    }

                    Handle = sessionPtr;
                }
            }
            finally
            {
                if (sessionConfig.ApplicationKey != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(sessionConfig.ApplicationKey);
                    sessionConfig.ApplicationKey = IntPtr.Zero;
                }
            }

            _mainThreadNotification  = new AutoResetEvent(false);
            _mainThread              = new Thread(MainThreadLoop);
            _mainThread.Name         = "MainLoop";
            _mainThread.IsBackground = true;
            _mainThread.Start();

            _eventQueue = new Queue <DelegateInvoker>();

            _eventThread              = new Thread(EventThreadLoop);
            _eventThread.Name         = "EventLoop";
            _eventThread.IsBackground = true;
            _eventThread.Start();

            AppDomain.CurrentDomain.ProcessExit += OnHostProcessExit;
        }
Exemplo n.º 3
0
        public override void Initialize()
        {
            _callbacks = new NativeSessionCallbacks(this);

            var sessionConfig = new Spotify.SpotifySessionConfig
            {
                ApiVersion = Spotify.SPOTIFY_API_VERSION,
                CacheLocation = _cacheLocation,
                SettingsLocation = _settingsLocation,
                UserAgent = _userAgent,
                CompressPlaylists = false,
                DontSaveMetadataForPlaylists = false,
                InitiallyUnloadPlaylists = false,
                ApplicationKey = Marshal.AllocHGlobal(_applicationKey.Length),
                ApplicationKeySize = _applicationKey.Length,
                Callbacks = _callbacks.CallbackHandle
            };

            try
            {
                Marshal.Copy(_applicationKey, 0, sessionConfig.ApplicationKey, _applicationKey.Length);

                lock (Spotify.Mutex)
                {
                    IntPtr sessionPtr;
                    Error res = Spotify.sp_session_create(ref sessionConfig, out sessionPtr);

                    if (res != Error.OK)
                    {
                        throw new Exception(res.GetMessage());
                    }

                    Handle = sessionPtr;
                }
            }
            finally
            {
                if (sessionConfig.ApplicationKey != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(sessionConfig.ApplicationKey);
                    sessionConfig.ApplicationKey = IntPtr.Zero;
                }
            }

            _friends = new DelegateArray<IUser>(GetNumberOfFriends, GetFriendAtIndex);

            _mainThreadNotification = new AutoResetEvent(false);
            _mainThread = new Thread(MainThreadLoop);
            _mainThread.Name = "MainLoop";
            _mainThread.IsBackground = true;
            _mainThread.Start();

            _eventQueue = new Queue<DelegateInvoker>(2000);

            _eventThreadNotification = new AutoResetEvent(false);
            _eventThread = new Thread(EventThreadLoop);
            _eventThread.Name = "EventLoop";
            _eventThread.IsBackground = true;
            _eventThread.Start();

            AppDomain.CurrentDomain.ProcessExit += OnHostProcessExit;
        }