Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
Added support for creating playlists.
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
Alxandr committed Aug 19, 2011
1 parent 0162509 commit b3ffcb2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SpotiFire.SpotifyLib/Interfaces/IPlaylistContainer.cs
Expand Up @@ -3,7 +3,7 @@
public interface IPlaylistContainer : ISpotifyObject
{
//IUser User {get;}
IEditableArray<IContainerPlaylist> Playlists { get; }
IPlaylistList Playlists { get; }
bool IsLoaded { get; }
event PlaylistContainerHandler Loaded;
event PlaylistContainerHandler<PlaylistEventArgs> PlaylistAdded;
Expand Down
8 changes: 8 additions & 0 deletions SpotiFire.SpotifyLib/Interfaces/IPlaylistList.cs
@@ -0,0 +1,8 @@

namespace SpotiFire.SpotifyLib
{
public interface IPlaylistList : IEditableArray<IContainerPlaylist>
{
IContainerPlaylist Add(string name);
}
}
19 changes: 19 additions & 0 deletions SpotiFire.SpotifyLib/PlaylistList.cs
@@ -0,0 +1,19 @@

using System;
namespace SpotiFire.SpotifyLib
{
class PlaylistList : DelegateList<IContainerPlaylist>, IPlaylistList
{
private Func<string, IContainerPlaylist> addNewFunc;
public PlaylistList(Func<int> getLength, Func<int, IContainerPlaylist> getIndex, Action<IContainerPlaylist, int> addFunc, Action<int> removeFunc, Func<bool> readonlyFunc, Func<string, IContainerPlaylist> addNewFunc)
: base(getLength, getIndex, addFunc, removeFunc, readonlyFunc)
{

}

public IContainerPlaylist Add(string name)
{
return addNewFunc(name);
}
}
}
2 changes: 2 additions & 0 deletions SpotiFire.SpotifyLib/SpotiFire.SpotifyLib.csproj
Expand Up @@ -46,11 +46,13 @@
<Compile Include="Interfaces\IAlbumBrowse.cs" />
<Compile Include="Interfaces\IArtistBrowse.cs" />
<Compile Include="Interfaces\IContainerPlaylist.cs" />
<Compile Include="Interfaces\IPlaylistList.cs" />
<Compile Include="Interfaces\IPlaylistTrack.cs" />
<Compile Include="Interfaces\ILink.cs" />
<Compile Include="Interfaces\IPlaylistTrackList.cs" />
<Compile Include="LinkExtensions.cs" />
<Compile Include="Interfaces\ITrackAndOffset.cs" />
<Compile Include="PlaylistList.cs" />
<Compile Include="PlaylistTrackList.cs" />
<Compile Include="SpotifyLibExtensions.cs" />
<Compile Include="SpotifyTypes\AlbumBrowse.cs" />
Expand Down
22 changes: 17 additions & 5 deletions SpotiFire.SpotifyLib/SpotifyTypes/PlaylistContainer.cs
Expand Up @@ -74,7 +74,7 @@ public ISession Session
get { IsAlive(true); return pc.Session; }
}

public IEditableArray<IContainerPlaylist> Playlists
public IPlaylistList Playlists
{
get { IsAlive(true); return pc.Playlists; }
}
Expand Down Expand Up @@ -151,7 +151,7 @@ private struct sp_playlistcontainer_callbacks
private playlist_moved_cb playlist_moved;
private container_loaded_cb container_loaded;

private IEditableArray<IContainerPlaylist> playlists;
private PlaylistList playlists;
private bool loaded;
#endregion

Expand Down Expand Up @@ -190,7 +190,7 @@ private PlaylistContainer(Session session, IntPtr pcPtr)

session.DisposeAll += new SessionEventHandler(session_DisposeAll);

playlists = new DelegateList<IContainerPlaylist>(
playlists = new PlaylistList(
() =>
{
IsAlive(true);
Expand Down Expand Up @@ -224,7 +224,19 @@ private PlaylistContainer(Session session, IntPtr pcPtr)
lock (libspotify.Mutex)
libspotify.sp_playlistcontainer_remove_playlist(pcPtr, index);
},
() => false
() => false,
(name) =>
{
IsAlive(true);
IntPtr playlistPtr;
int index;
lock (libspotify.Mutex)
{
playlistPtr = libspotify.sp_playlistcontainer_add_new_playlist(pcPtr, name);
index = playlistPtr == IntPtr.Zero ? -1 : libspotify.sp_playlistcontainer_num_playlists(pcPtr) - 1;
}
return index == -1 ? null : playlists[index];
}
);
}

Expand All @@ -235,7 +247,7 @@ void session_DisposeAll(ISession sender, SessionEventArgs e)
#endregion

#region Properties
public IEditableArray<IContainerPlaylist> Playlists
public IPlaylistList Playlists
{
get { return playlists; }
}
Expand Down

0 comments on commit b3ffcb2

Please sign in to comment.