Permalink
Browse files

Fixed some crashes, added track_complete

  • Loading branch information...
1 parent deef0a2 commit 00e8c12e598589fc7e329f426ccdb8c264f24bfe @Alxandr committed Nov 2, 2012
@@ -98,7 +98,7 @@ SP_CALL log_message(sp_session *session, const char *message) {
}
SP_CALL end_of_track(sp_session *session) {
-
+ TP0(SESSION, Session::end_of_track);
}
SP_CALL streaming_error(sp_session *session, sp_error error) {
@@ -295,7 +295,11 @@ PlaylistContainer ^Session::PlaylistContainer::get() {
}
Playlist ^Session::Starred::get() {
- throw gcnew NotImplementedException("starred get");
+ SPLock lock;
+ sp_playlist *ptr = sp_session_starred_create(_ptr);
+ auto ret = gcnew Playlist(this, ptr);
+ sp_playlist_release(ptr);
+ return ret;
}
void Session::PrefferedBitrate::set(BitRate bitRate) {
@@ -313,4 +317,8 @@ void Session::logged_in(Error error) {
void Session::logged_out() {
_logout->SetResult(true);
+}
+
+void Session::end_of_track() {
+ EndOfTrack(this, gcnew SessionEventArgs());
}
@@ -43,6 +43,7 @@ namespace SpotiFire {
void logged_in(Error error);
void logged_out();
void music_delivery(MusicDeliveryEventArgs ^e);
+ void end_of_track();
public:
virtual property ConnectionState ConnectionState { SpotiFire::ConnectionState get() sealed; }
@@ -94,4 +94,26 @@ __forceinline void __TP1(Action<T1> ^action, T1 val1) {
auto _wc = gcnew WaitCallback(wc, &$WaitCallback1<T1>::Callback);
ThreadPool::QueueUserWorkItem(_wc);
}
-#define TP1(type1, object, func, val1) __TP1<type1>(gcnew Action<type1>(object, &func), val1)
+#define TP1(type1, object, func, val1) __TP1<type1>(gcnew Action<type1>(object, &func), val1)
+
+generic<typename T1, typename T2>
+ref struct $WaitCallback2 {
+ T1 _val1;
+ T2 _val2;
+ System::Action<T1, T2> ^_cb;
+ $WaitCallback2(Action<T1, T2> ^cb, T1 val1, T2 val2) {
+ _cb = cb;
+ _val1 = val1;
+ _val2 = val2;
+ }
+ void Callback(Object ^state) {
+ _cb(_val1, _val2);
+ }
+};
+generic<typename T1, typename T2>
+__forceinline void __TP2(System::Action<T1, T2> ^action, T1 val1, T2 val2) {
+ auto wc = gcnew $WaitCallback2<T1, T2>(action, val1, val2);
+ auto _wc = gcnew WaitCallback(wc, &$WaitCallback2<T1, T2>::Callback);
+ ThreadPool::QueueUserWorkItem(_wc);
+}
+#define TP2(type1, type2, object, func, val1, val2) __TP2<type1, type2>(gcnew System::Action<type1, type2>(object, &func), val1, val2)
@@ -40,7 +40,7 @@ internal static void OnComplete(ISpotifyAwaitable awaitable, Action continuation
_continuation = new Continuation(continuation, false);
if (!awaitable.AddContinuation(() => _continuation.Run(awaitable, true)))
{
- UnsafeScheduleAction(continuation);
+ UnsafeScheduleAction(awaitable, continuation);
}
}
else
@@ -98,12 +98,6 @@ public Continuation (Action action, bool flowExecutionContext)
_capturedContext = ExecutionContext.Capture();
}
- public virtual void WaitCallback(object state)
- {
- RunCallback(GetInvokeActionCallback(), _action);
- }
-
-
public virtual void Run(ISpotifyAwaitable awaitable, bool canInlineContinueTask)
{
RunCallback(GetInvokeActionCallback(), _action);
@@ -155,11 +149,6 @@ static SynchronizationContextContinuation()
_postCallback = (object state) => ((Action)state)();
}
- public override void WaitCallback(object state)
- {
- throw new NotImplementedException();
- }
-
[SecurityCritical]
static ContextCallback GetPostActionCallback()
{
@@ -190,9 +179,11 @@ public override void Run(ISpotifyAwaitable awaitable, bool canInlineContinueTask
}
}
- static void UnsafeScheduleAction(Action action)
+ static void UnsafeScheduleAction(ISpotifyAwaitable awaitable, Action action)
{
- ThreadPool.UnsafeQueueUserWorkItem(new Continuation(action, false).WaitCallback, null);
+ ThreadPool.UnsafeQueueUserWorkItem(delegate {
+ new Continuation(action, false).Run(awaitable, true);
+ }, null);
}
public struct AwaitableAwaiter<T> : ICriticalNotifyCompletion
@@ -53,14 +53,19 @@ static void Main(string[] args)
session.PrefferedBitrate = 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));
+ }
var playlist = await session.PlaylistContainer.Playlists[0];
- Console.WriteLine("Playing first from " + playlist.Name);
- var track = await playlist.Tracks[0];
+ Console.WriteLine("Playing random from " + playlist.Name);
+ var track = await playlist.Tracks[new Random().Next(playlist.Tracks.Count)];
await session.Play(track);
playlist = await session.Starred;
- Console.WriteLine("Playing first starred track");
- track = await playlist.Tracks[0];
+ 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);
View
@@ -80,9 +80,13 @@
<sources basedir="${basedir}/SpotiFire.SpotifyLib">
<include name="**.cs" />
</sources>
+ <nowarn>
+ <warning number="1684" /> <!-- do not report warnings for extern members not found -->
+ <warning number="1591" /> <!-- do not report warnings for missing XML comments -->
+ </nowarn>
</csc>
- <link output="${build.obj}/${name}.dll" options="/LTCG /FIXED /CLRIMAGETYPE:IJW /NOENTRY /DLL">
+ <link output="${build.obj}/${name}.dll" options="/LTCG /FIXED /CLRIMAGETYPE:IJW /NOENTRY /DLL /ignore:4248">
<sources basedir="${build.obj}">
<include name="*.obj" />
<include name="*.netmodule" />
Oops, something went wrong.

0 comments on commit 00e8c12

Please sign in to comment.