private Session(byte[] applicationKey, string cacheLocation, string settingsLocation, string userAgent) { ProcExit = false; libspotify.sp_session_config config = new libspotify.sp_session_config(); config.api_version = libspotify.SPOTIFY_API_VERSION; config.cache_location = cacheLocation; config.settings_location = settingsLocation; config.user_agent = userAgent; config.compress_playlists = false; config.dont_save_metadata_for_playlists = false; config.initially_unload_playlists = false; int size = Marshal.SizeOf(callbacks); config.callbacks = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(callbacks, config.callbacks, true); config.application_key = IntPtr.Zero; try { config.application_key = Marshal.AllocHGlobal(applicationKey.Length); Marshal.Copy(applicationKey, 0, config.application_key, applicationKey.Length); lock (libspotify.Mutex) config.application_key_size = applicationKey.Length; sessionPtr = IntPtr.Zero; sp_error res = libspotify.sp_session_create(ref config, out sessionPtr); if (res != sp_error.OK) { throw new SpotifyException(res); } mainThread = new Thread(new ThreadStart(MainThread)); mainThread.IsBackground = true; mainThread.Start(); eventThread = new Thread(new ThreadStart(EventThread)); eventThread.IsBackground = true; eventThread.Start(); } finally { if (config.application_key != IntPtr.Zero) { Marshal.FreeHGlobal(config.application_key); } } AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_OnExit); AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_OnExit); }
private static libspotify.sp_error initSession() { libspotify.sp_session_callbacks callbacks = new libspotify.sp_session_callbacks(); callbacks.connection_error = Marshal.GetFunctionPointerForDelegate(fn_connection_error_delegate); callbacks.end_of_track = Marshal.GetFunctionPointerForDelegate(fn_end_of_track_delegate); callbacks.get_audio_buffer_stats = Marshal.GetFunctionPointerForDelegate(fn_get_audio_buffer_stats_delegate); callbacks.log_message = Marshal.GetFunctionPointerForDelegate(fn_log_message); callbacks.logged_in = Marshal.GetFunctionPointerForDelegate(fn_logged_in_delegate); callbacks.logged_out = Marshal.GetFunctionPointerForDelegate(fn_logged_out_delegate); callbacks.message_to_user = Marshal.GetFunctionPointerForDelegate(fn_message_to_user_delegate); callbacks.metadata_updated = Marshal.GetFunctionPointerForDelegate(fn_metadata_updated_delegate); callbacks.music_delivery = Marshal.GetFunctionPointerForDelegate(fn_music_delivery_delegate); callbacks.notify_main_thread = Marshal.GetFunctionPointerForDelegate(fn_notify_main_thread_delegate); callbacks.offline_status_updated = Marshal.GetFunctionPointerForDelegate(fn_offline_status_updated_delegate); callbacks.play_token_lost = Marshal.GetFunctionPointerForDelegate(fn_play_token_lost_delegate); callbacks.start_playback = Marshal.GetFunctionPointerForDelegate(fn_start_playback); callbacks.stop_playback = Marshal.GetFunctionPointerForDelegate(fn_stop_playback); callbacks.streaming_error = Marshal.GetFunctionPointerForDelegate(fn_streaming_error_delegate); callbacks.userinfo_updated = Marshal.GetFunctionPointerForDelegate(fn_userinfo_updated_delegate); IntPtr callbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(callbacks)); Marshal.StructureToPtr(callbacks, callbacksPtr, true); libspotify.sp_session_config config = new libspotify.sp_session_config(); config.api_version = libspotify.SPOTIFY_API_VERSION; config.user_agent = "BlindSpot"; config.application_key_size = appkey.Length; config.application_key = Marshal.AllocHGlobal(appkey.Length); config.cache_location = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Blindspot\\Libspotify"); config.settings_location = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Blindspot\\Libspotify"); config.callbacks = callbacksPtr; config.compress_playlists = true; config.dont_save_metadata_for_playlists = false; config.initially_unload_playlists = false; Logger.WriteDebug("api_version={0}", config.api_version); Logger.WriteDebug("application_key_size={0}", config.application_key_size); Logger.WriteDebug("cache_location={0}", config.cache_location); Logger.WriteDebug("settings_location={0}", config.settings_location); Marshal.Copy(appkey, 0, config.application_key, appkey.Length); IntPtr sessionPtr; libspotify.sp_error err = libspotify.sp_session_create(ref config, out sessionPtr); if (err == libspotify.sp_error.OK) { _sessionPtr = sessionPtr; libspotify.sp_session_set_connection_type(sessionPtr, libspotify.sp_connection_type.SP_CONNECTION_TYPE_WIRED); } return(err); }
private static libspotify.sp_error initSession() { lock (_lock) { waveOut = new WaveOut(); libspotify.sp_session_callbacks callbacks = new libspotify.sp_session_callbacks(); callbacks.connection_error = Marshal.GetFunctionPointerForDelegate(fn_connection_error_delegate); callbacks.end_of_track = Marshal.GetFunctionPointerForDelegate(fn_end_of_track_delegate); callbacks.get_audio_buffer_stats = Marshal.GetFunctionPointerForDelegate(fn_get_audio_buffer_stats_delegate); callbacks.log_message = Marshal.GetFunctionPointerForDelegate(fn_log_message); callbacks.logged_in = Marshal.GetFunctionPointerForDelegate(fn_logged_in_delegate); callbacks.logged_out = Marshal.GetFunctionPointerForDelegate(fn_logged_out_delegate); callbacks.message_to_user = Marshal.GetFunctionPointerForDelegate(fn_message_to_user_delegate); callbacks.metadata_updated = Marshal.GetFunctionPointerForDelegate(fn_metadata_updated_delegate); callbacks.music_delivery = Marshal.GetFunctionPointerForDelegate(fn_music_delivery_delegate); callbacks.notify_main_thread = Marshal.GetFunctionPointerForDelegate(fn_notify_main_thread_delegate); callbacks.offline_status_updated = Marshal.GetFunctionPointerForDelegate(fn_offline_status_updated_delegate); callbacks.play_token_lost = Marshal.GetFunctionPointerForDelegate(fn_play_token_lost_delegate); callbacks.start_playback = Marshal.GetFunctionPointerForDelegate(fn_start_playback); callbacks.stop_playback = Marshal.GetFunctionPointerForDelegate(fn_stop_playback); callbacks.streaming_error = Marshal.GetFunctionPointerForDelegate(fn_streaming_error_delegate); callbacks.userinfo_updated = Marshal.GetFunctionPointerForDelegate(fn_userinfo_updated_delegate); IntPtr callbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(callbacks)); Marshal.StructureToPtr(callbacks, callbacksPtr, true); libspotify.sp_session_config config = new libspotify.sp_session_config(); config.api_version = libspotify.SPOTIFY_API_VERSION; config.user_agent = "SoundBounce"; config.application_key_size = appkey.Length; config.application_key = Marshal.AllocHGlobal(appkey.Length); config.cache_location = Path.Combine(Path.GetTempPath(), "SoundBounce_temp"); config.settings_location = Path.Combine(Path.GetTempPath(), "SoundBounce_temp"); config.callbacks = callbacksPtr; config.compress_playlists = true; config.dont_save_metadata_for_playlists = false; config.initially_unload_playlists = false; Spotify.Log.DebugFormat("api_version={0}", config.api_version); Spotify.Log.DebugFormat("api_version={0}", config.api_version); Spotify.Log.DebugFormat("application_key_size={0}", config.application_key_size); Spotify.Log.DebugFormat("cache_location={0}", config.cache_location); Spotify.Log.DebugFormat("settings_location={0}", config.settings_location); Marshal.Copy(appkey, 0, config.application_key, appkey.Length); IntPtr sessionPtr; libspotify.sp_error err = libspotify.sp_session_create(ref config, out sessionPtr); if (err == libspotify.sp_error.OK) { _sessionPtr = sessionPtr; libspotify.sp_session_set_connection_type(sessionPtr, libspotify.sp_connection_type.SP_CONNECTION_TYPE_WIRED); } // set high bitrate if (ConfigurationManager.AppSettings["HighBitrate"] == "true") { libspotify.sp_error test = libspotify.sp_session_preferred_bitrate(sessionPtr, libspotify.sp_bitrate .BITRATE_320k); if (test != libspotify.sp_error.OK) { Spotify.Log.WarnFormat("sp_session_preferred_bitrate() to 320k failed: {0}", test); } else { Spotify.Log.Debug("sp_session_preferred_bitrate() to 320k succeeded!"); } } // normalize volume if (ConfigurationManager.AppSettings["NormalizeVolume"] == "true") { libspotify.sp_session_set_volume_normalization(sessionPtr, true); } return(err); } }
private static libspotify.sp_error initSession(string appname) { libspotify.sp_session_callbacks callbacks = new libspotify.sp_session_callbacks(); callbacks.connection_error = Marshal.GetFunctionPointerForDelegate(fn_connection_error_delegate); callbacks.end_of_track = Marshal.GetFunctionPointerForDelegate(fn_end_of_track_delegate); callbacks.get_audio_buffer_stats = Marshal.GetFunctionPointerForDelegate(fn_get_audio_buffer_stats_delegate); callbacks.log_message = Marshal.GetFunctionPointerForDelegate(fn_log_message); callbacks.logged_in = Marshal.GetFunctionPointerForDelegate(fn_logged_in_delegate); callbacks.logged_out = Marshal.GetFunctionPointerForDelegate(fn_logged_out_delegate); callbacks.message_to_user = Marshal.GetFunctionPointerForDelegate(fn_message_to_user_delegate); callbacks.metadata_updated = Marshal.GetFunctionPointerForDelegate(fn_metadata_updated_delegate); callbacks.music_delivery = Marshal.GetFunctionPointerForDelegate(fn_music_delivery_delegate); callbacks.notify_main_thread = Marshal.GetFunctionPointerForDelegate(fn_notify_main_thread_delegate); callbacks.offline_status_updated = Marshal.GetFunctionPointerForDelegate(fn_offline_status_updated_delegate); callbacks.play_token_lost = Marshal.GetFunctionPointerForDelegate(fn_play_token_lost_delegate); callbacks.start_playback = Marshal.GetFunctionPointerForDelegate(fn_start_playback); callbacks.stop_playback = Marshal.GetFunctionPointerForDelegate(fn_stop_playback); callbacks.streaming_error = Marshal.GetFunctionPointerForDelegate(fn_streaming_error_delegate); callbacks.userinfo_updated = Marshal.GetFunctionPointerForDelegate(fn_userinfo_updated_delegate); callbacks.scrobble_error = Marshal.GetFunctionPointerForDelegate(fn_scrobble_error_delegate); IntPtr callbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(callbacks)); Marshal.StructureToPtr(callbacks, callbacksPtr, true); libspotify.sp_session_config config = new libspotify.sp_session_config(); config.api_version = libspotify.SPOTIFY_API_VERSION; config.user_agent = appname; config.application_key_size = appkey.Length; config.application_key = Marshal.AllocHGlobal(appkey.Length); config.cache_location = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appname, "spotifycache"); config.settings_location = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appname, "spotifysettings"); config.callbacks = callbacksPtr; config.compress_playlists = true; config.dont_save_metadata_for_playlists = false; config.initially_unload_playlists = false; Log.Debug(Plugin.LOG_MODULE, "api_version={0}", config.api_version); Log.Debug(Plugin.LOG_MODULE, "application_key_size={0}", config.application_key_size); Log.Debug(Plugin.LOG_MODULE, "cache_location={0}", config.cache_location); Log.Debug(Plugin.LOG_MODULE, "settings_location={0}", config.settings_location); Marshal.Copy(appkey, 0, config.application_key, appkey.Length); IntPtr sessionPtr; libspotify.sp_error err = libspotify.sp_session_create(ref config, out sessionPtr); libspotify.sp_session_set_cache_size(sessionPtr, 0); if (err == libspotify.sp_error.OK) { _sessionPtr = sessionPtr; libspotify.sp_session_set_connection_type(sessionPtr, libspotify.sp_connection_type.SP_CONNECTION_TYPE_WIRED); } libspotify.sp_error test = libspotify.sp_session_preferred_bitrate(sessionPtr, libspotify.sp_bitrate.BITRATE_320k); if (test != libspotify.sp_error.OK) { Log.Warning(Plugin.LOG_MODULE, "sp_session_preferred_bitrate() failed: {0}", test); } else { Log.Debug(Plugin.LOG_MODULE, "sp_session_preferred_bitrate() succeeded!"); } return(err); }