Alxandr / SpotiFire

A project to make a SpotifyClient in C#
http://nudoc.azurewebsites.net/SpotiFire
40 stars 19 forks source link

Further unimplemented methods : Playlist creation, addition and removal #45

Closed brianavid closed 10 years ago

brianavid commented 10 years ago

$PlaylistContainer$PlaylistList does not implement DoInsert() or DoRemove(), which I discovered part way though adding playlist management to my system (which is otherwise working GREAT so far - thanks).

But even if there is a DoInsert(), Playlist has no constructor, so nothing can currently be created to be added.

The native method for what I need is sp_playlistcontainer_add_new_playlist(), but I can't work out how to fit it into the current class structure as it combines a Playlist constructor with the insertion into a PlaylistContainer.

Any ideas??

Meanwhile I shall live without the ability to add new playlists.

elikrief commented 10 years ago

Hi, First of all, thanks for your work, it's a great dll. I need the ability to create and synchronize playlists to. can you help me for this ? thx

Alxandr commented 10 years ago

Yeah. I'm on it, though there's a lot I want to implement in SpotiFire (some big changes are in progress) - se branch feature-buffer and feature-synchronization for instance, so I'm not sure when I can do it. I also have work at, but I'll try to get it done as fast as possible.

elikrief commented 10 years ago

Hi, thanks for the quick answer. i'm working on a itunes->spotify playlist sync module, and I 'm stuck ... :(

Alxandr commented 10 years ago

I'll see if I can through together something quick for you during the weekend. Du note however that the API might (and probably will) change in the future. The SpotiFire API is still considered unstable.

elikrief commented 10 years ago

thanks a lot.

Alxandr commented 10 years ago

I'm sorry, but I really have a lot on my plate. This was thrown together quickly. Take a look at the branch containing the playlist-creation commit. Adding removal etc. should be fairly simple on your own. Or you can try and get a hold of Chris and see if he has time.

elikrief commented 10 years ago

I will check this . thanks a lot

Xstasy commented 10 years ago

Playlists.Create(string name) produces a AccessViolationException.

brianavid commented 10 years ago

I can create a Playlist using Playlists.Create(string name), but I can't do anything with it because both SPList.Add() and SPList.Insert() refuse to act on an empty list. So I can't insert any track into it.

Oops!?!

brianavid commented 10 years ago

Given how widely used the generic SPList is used, I am very uncomfortable in changing this to support adding to an empty list. Technically it should be quite easy, but the wider implications could be significant - i.e. it could break almost anything!

Is there anyone lurking that has a greater understanding of the uses of these lists?

Alxandr commented 10 years ago

What do you mean SPList.Insert refuses to act on an empty list? What exceptions are you seeing?

brianavid commented 10 years ago

Add() is Insert(Count - 1, item) Insert has :+1: if(index < 0 || index >= DoCount()) throw gcnew IndexOutOfRangeException();

Sp when Count == 0, we always get this exception.

Alxandr commented 10 years ago

If anybody would do some testing as to if the track is inserted at the right index, I'd be most pleased.

brianavid commented 10 years ago

It is currently out-by-one. Add() inserts before the last existing track

ChrisBrandhorst commented 10 years ago

Playlist & Track adding and removal seem to be working correct in this branch now. I'll implement the moving of tracks.

Playlists also need to be moved, but because the PlaylistContainer (PlaylistList) should also support folders, some different approach has to be devised for that.

Please acknowledge the adding and removal works for you, so we can close this issue.

brianavid commented 10 years ago

Adding an empty playlist and adding and removing tracks now seems to work just fine - thanks

Brian

elikrief commented 10 years ago

hi , I'm test the whole playlist sync feature and I noticed that we cannot delete a playlist ...

ChrisBrandhorst commented 10 years ago

@elikrief Thanks for the comment, I'll check it out. I'm guessing I forgot to commit some parts...

elikrief commented 10 years ago

also , I'm trying to execute the code from an ASP.Net project and the spotifire.native.dll cannot be loaded. do you have an idea how to compile it to allow it to be loaded ?

Alxandr commented 10 years ago

@elikrief You'r ASP.Net application is probably running in medium trust. That might cause issues.

elikrief commented 10 years ago

nop... It's in full trust mode and still not working . you can just add a website project into the solution and add references, and you 'll see the loading error

Alxandr commented 10 years ago

@elikrief I'm not too surpriced about it not working in a website, but what error exactly are you getting?

elikrief commented 10 years ago

Could not load file or assembly 'SpotiFire.Native.DLL' or one of its dependencies. The specified module could not be found. the dll exists in the bin folder adding a website in the solution and references took 1 min and you'll can see the error and try to debug

elikrief commented 10 years ago

do you have some good news for me ?

ChrisBrandhorst commented 10 years ago

@elikrief Please check it out

elikrief commented 10 years ago

i will check it. thanks . what about the website issue , did you find something ?

elikrief commented 10 years ago

Hi, after calling twice playlists.create i'm getting an AccessViolationException.

ChrisBrandhorst commented 10 years ago

Works fine for me, with or without await-ing the calls. Can you post a relevant code block?

elikrief commented 10 years ago

//create playlist
Playlist spPlaylist = null;
PlaylistContainer container = await Session.PlaylistContainer; spPlaylist = await container.Playlists.Create(playlistName);

//*****adding and removing tracks (not relevant I think)

//get updated playlist (maybe this is the problem) spPlaylist = await Session.ParseLink(spPlaylist.GetLink().ToString()).AsPlaylist(); await LoadTracks(spPlaylist);

after calling this method once I 've got the error on the next try

ChrisBrandhorst commented 10 years ago

Sorry, that won't do (can't reproduce it). Please post a minimal section of test-code without using sub-methods, track loading etc. to show the error.

elikrief commented 10 years ago

hi, do you have some updates regarding the website issue ?

Alxandr commented 10 years ago

No. Nor do I have time to work on it currently. I might be able to look at it come christmas (ie. after the semester is done), but I doubt I can do it any sooner. However, I know from previous experimenting that you can get it to work with self hosted WebAPI (I had a working server that listed my playlists in browser and played the tracks when I clicked on them). Why it doesn't work in IIS/ASP I don't know.

brianavid commented 10 years ago

@elikrief

I agree that an external Spotify service is the way to go. Running it within the context of an IIS-hosted ASP.Net application doesn't work.

Look at (and feel free to copy and adapt) by GitHub project brianavid/Avid.Net4G. That has two components which are relevant. The Avid.Spotify project is an application which is run as administrator and sits in the desktop tray. It can play music from Spotify and is controlled ONLY from a Web API.

Inside the Avid4.Net project there is a class in Classes\Spotify.cs which is a clean API wrapper around the web API. This class can be linked into your IIS ASP.Net application, which is what the Avid4.Net application does.

You also need the shared interface project Avid.Spotify.Data, and you will have to provide your own spotify_appkey.key file. But I believe this approach will work for you.

I will be documenting the complete Avid.Net4G design in due course to allow wider use, but the code is already available and freely licensed.

Brian

Alxandr commented 10 years ago

Ok, this issue has gone way of topic. @ChrisBrandhorst did we add creation and deletion of Playlists? If so, please close this issue.

ChrisBrandhorst commented 10 years ago

Yes, is added. @elikrief had an issue, but could not supply a clear reproduction case. Will close. If issue persists, please open new issue with specific case.

elikrief commented 10 years ago

after adding and removing tracks I see that spPlaylist.HasPendingChanges == true. after that every call to await container.Playlists.Create failed with a "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Alxandr commented 10 years ago

Can you create a small working program that illustrates this issue?