banshee r3315 - in trunk/banshee: . src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler src/Libraries/Lastfm/Lastfm
- From: ahixon svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3315 - in trunk/banshee: . src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler src/Libraries/Lastfm/Lastfm
- Date: Sun, 24 Feb 2008 02:03:36 +0000 (GMT)
Author: ahixon
Date: Sun Feb 24 02:03:36 2008
New Revision: 3315
URL: http://svn.gnome.org/viewvc/banshee?rev=3315&view=rev
Log:
2008-02-23 Alexander Hixon <hixon alexander mediati org>
* src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs:
Rewrote the SongTimer class to use PlayerEngine.Position. Doesn't rely on
PlayerEngineState events anymore. This also means that SongTimer works well while
listening to songs on Last.fm.
* src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/Queue.cs:
* src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs: Implement MusicBrainzId
property and using that data to generate requests to Last.fm. Currently isn't
attached to any real data source, so the ID is always empty.
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs
trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/Queue.cs
trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs (original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs Sun Feb 24 02:03:36 2008
@@ -91,7 +91,6 @@
};
ServiceManager.PlayerEngine.EventChanged += OnPlayerEngineEventChanged;
- ServiceManager.PlayerEngine.StateChanged += OnPlayerEngineStateChanged;
action_service = ServiceManager.Get<InterfaceActionService> ("InterfaceActionService");
InterfaceInitialize ();
@@ -131,7 +130,6 @@
public void Dispose ()
{
ServiceManager.PlayerEngine.EventChanged -= OnPlayerEngineEventChanged;
- ServiceManager.PlayerEngine.StateChanged -= OnPlayerEngineStateChanged;
connection.Stop ();
@@ -140,26 +138,48 @@
actions = null;
}
- void OnPlayerEngineStateChanged (object o, PlayerEngineStateArgs args)
- {
- if (ServiceManager.PlayerEngine.CurrentState == PlayerEngineState.Paused &&
- ServiceManager.PlayerEngine.LastState == PlayerEngineState.Playing) {
- st.Stop ();
- }
- else if (ServiceManager.PlayerEngine.CurrentState == PlayerEngineState.Playing &&
- ServiceManager.PlayerEngine.LastState == PlayerEngineState.Paused) {
- st.Start ();
- }
- }
-
// We need to time how long the song has played
internal class SongTimer
{
- private DateTime start_time;
- public int PlayTime = 0;
- public void Start() { start_time = DateTime.Now; }
- public void Stop() { PlayTime += (int) (DateTime.Now - start_time).TotalSeconds;}
- public void Reset() { PlayTime = 0; }
+ private long playtime = 0; // number of msecs played
+ public long PlayTime {
+ get { return playtime; }
+ }
+
+ private long previouspos = 0;
+
+ // number of events to ignore to get sync (since events may be fired in wrong order)
+ private int ignorenext = 0;
+
+ public void IncreasePosition ()
+ {
+ long increase = 0;
+
+ if (ignorenext == 0) {
+ increase = (ServiceManager.PlayerEngine.Position - previouspos);
+ playtime += increase;
+ } else {
+ ignorenext--;
+ }
+
+ previouspos = ServiceManager.PlayerEngine.Position;
+
+ //Console.WriteLine ("Position now {0} (increased by {1} msec) : {2}", playtime, increase, ignorenext);
+ }
+
+ public void SkipPosition ()
+ {
+ // Set newly seeked position
+ previouspos = ServiceManager.PlayerEngine.Position;
+ ignorenext = 2; // allow 2 iterates to sync
+ }
+
+ public void Reset ()
+ {
+ playtime = 0;
+ previouspos = 0;
+ ignorenext = 0;
+ }
}
SongTimer st = new SongTimer ();
@@ -169,12 +189,12 @@
return;
}
- Log.DebugFormat ("Track {4} had playtime of {0} sec, duration {1} sec, started: {2}, queued: {3}",
- st.PlayTime, track.Duration.TotalSeconds, song_started, queued, track);
+ Log.DebugFormat ("Track {4} had playtime of {0} msec ({5}sec), duration {1} msec, started: {2}, queued: {3}",
+ st.PlayTime, track.Duration.TotalMilliseconds, song_started, queued, track, st.PlayTime / 1000);
if (song_started && !queued && track.Duration.TotalSeconds > 30 &&
track.ArtistName != "" && track.TrackTitle != "" &&
- (st.PlayTime > track.Duration.TotalSeconds / 2 || st.PlayTime > 240)) {
+ (st.PlayTime > track.Duration.TotalMilliseconds / 2 || st.PlayTime > 240 * 1000)) {
queue.Add (track, song_start_time);
queued = true;
}
@@ -185,10 +205,9 @@
switch (args.Event) {
case PlayerEngineEvent.StartOfStream:
// Queue the previous track in case of a skip
- st.Stop ();
Queue (last_track);
- st.Reset (); st.Start ();
+ st.Reset ();
song_start_time = DateTime.Now;
last_track = ServiceManager.PlayerEngine.CurrentTrack;
queued = false;
@@ -202,8 +221,15 @@
break;
+ case PlayerEngineEvent.Seek:
+ st.SkipPosition ();
+ break;
+
+ case PlayerEngineEvent.Iterate:
+ st.IncreasePosition ();
+ break;
+
case PlayerEngineEvent.EndOfStream:
- st.Stop ();
Queue (ServiceManager.PlayerEngine.CurrentTrack);
//queued = true;
break;
Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/Queue.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/Queue.cs (original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/Queue.cs Sun Feb 24 02:03:36 2008
@@ -40,6 +40,8 @@
using Banshee.Base;
using Banshee.Collection;
+using Banshee.ServiceStack;
+using Banshee.Sources;
using Lastfm;
@@ -57,10 +59,15 @@
this.track_number = (int) track.TrackNumber;
this.duration = (int) track.Duration.TotalSeconds;
this.start_time = DateTimeUtil.ToTimeT(start_time.ToLocalTime ());
+ // TODO
+ //this.musicbrainzid = track.MusicBrainzId;
+
+ this.musicbrainzid = "";
}
public QueuedTrack (string artist, string album,
- string title, int track_number, int duration, long start_time)
+ string title, int track_number, int duration, long start_time,
+ string musicbrainzid)
{
this.artist = artist;
this.album = album;
@@ -68,6 +75,7 @@
this.track_number = track_number;
this.duration = duration;
this.start_time = start_time;
+ this.musicbrainzid = musicbrainzid;
}
public long StartTime {
@@ -93,18 +101,24 @@
public int Duration {
get { return duration; }
}
+
+ public string MusicBrainzId {
+ get { return musicbrainzid; }
+ }
string artist;
string album;
string title;
int track_number;
int duration;
+ string musicbrainzid;
long start_time;
}
List<QueuedTrack> queue;
string xml_path;
bool dirty;
+ SourceManager sourcemanager;
public event EventHandler TrackAdded;
@@ -118,6 +132,8 @@
if (!Directory.Exists(xmlfilepath)) {
Directory.CreateDirectory (xmlfilepath);
}
+
+ sourcemanager = ServiceManager.Get<SourceManager> ("SourceManager");
Load ();
}
@@ -144,6 +160,7 @@
writer.WriteElementString ("TrackNumber", track.TrackNumber.ToString());
writer.WriteElementString ("Duration", track.Duration.ToString());
writer.WriteElementString ("StartTime", track.StartTime.ToString());
+ writer.WriteElementString ("MusicBrainzId", track.MusicBrainzId);
writer.WriteEndElement (); // Track
}
writer.WriteEndElement (); // AudioscrobblerQueue
@@ -154,7 +171,6 @@
public void Load ()
{
queue.Clear ();
-
try {
string query = "//AudioscrobblerQueue/QueuedTrack";
XmlDocument doc = new XmlDocument ();
@@ -169,6 +185,7 @@
int track_number = 0;
int duration = 0;
long start_time = 0;
+ string musicbrainzid = "";
foreach (XmlNode child in node.ChildNodes) {
if (child.Name == "Artist" && child.ChildNodes.Count != 0) {
@@ -183,10 +200,13 @@
duration = Convert.ToInt32 (child.ChildNodes [0].Value);
} else if (child.Name == "StartTime" && child.ChildNodes.Count != 0) {
start_time = Convert.ToInt64 (child.ChildNodes [0].Value);
+ } else if (child.Name == "MusicBrainzId" && child.ChildNodes.Count != 0) {
+ musicbrainzid = child.ChildNodes [0].Value;
}
}
- queue.Add (new QueuedTrack (artist, album, title, track_number, duration, start_time));
+ queue.Add (new QueuedTrack (artist, album, title, track_number, duration,
+ start_time, musicbrainzid));
}
} catch {
}
@@ -199,11 +219,11 @@
int i;
for (i = 0; i < queue.Count; i ++) {
- /* Last.FM 1.2 can handle up to 50 songs in one request */
+ /* Last.fm 1.2 can handle up to 50 songs in one request */
if (i == 49) break;
QueuedTrack track = (QueuedTrack) queue[i];
-
+
if (track.TrackNumber != 0)
str_track_number = track.TrackNumber.ToString();
@@ -217,8 +237,9 @@
track.Duration.ToString (),
HttpUtility.UrlEncode (track.Album),
str_track_number,
- "" /* musicbrainz id */,
- i);
+ track.MusicBrainzId,
+
+ i);
}
numtracks = i;
Modified: trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs (original)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs Sun Feb 24 02:03:36 2008
@@ -504,7 +504,14 @@
//
// Async code for now playing
- public void NowPlaying (string artist, string title, string album, double duration, int tracknum)
+ public void NowPlaying (string artist, string title, string album, double duration,
+ int tracknum)
+ {
+ NowPlaying (artist, title, album, duration, tracknum, "");
+ }
+
+ public void NowPlaying (string artist, string title, string album, double duration,
+ int tracknum, string mbrainzid)
{
if (session_id != null && artist != "" && title != "") {
@@ -521,7 +528,7 @@
HttpUtility.UrlEncode(album),
duration.ToString(),
str_track_number,
- "" /* musicbrainz id */);
+ mbrainzid);
now_playing_post = WebRequest.Create (uri);
now_playing_post.Method = "POST";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]