~ubuntu-branches/ubuntu/karmic/last-exit/karmic

« back to all changes in this revision

Viewing changes to src/Player.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2008-03-21 00:53:20 UTC
  • mfrom: (1.1.5 upstream) (4.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080321005320-u2l6gaaxn2mn0mbq
Tags: 6-1
* New upstream release:
  + debian/patches/01_dllmaps.patch,
    debian/patches/02_de.po.patch,
    debian/patches/03_gtk-sharp-2-12.patch:
    - Dropped, merged upstream.
  + debian/control.in:
    - Update build dependencies.
  + debian/patches/99_ltmain_as-needed.patch:
    - Updated to apply cleanly again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
        public class Player : GLib.Object {
35
35
                
36
 
                public delegate void NewSongHandler ();
 
36
                public delegate void NewSongHandler (Song song);
37
37
                public event NewSongHandler NewSong;
38
 
                
 
38
                public event NewSongHandler SongEnded;
39
39
                private SignalUtils.SignalDelegate new_song_cb;
 
40
                private SignalUtils.SignalDelegate end_song_cb;
 
41
                private SignalUtils.SignalDelegateStr error_cb;
40
42
                private bool playing;
41
43
 
 
44
                private Song current_song;
 
45
                private Playlist playlist;
 
46
                public Playlist Plist {
 
47
                        get { return playlist; }
 
48
                }
 
49
 
42
50
                // Constructor
43
51
                [DllImport ("liblastexit")]
44
52
                private static extern IntPtr player_new ();
45
53
 
46
 
                public Player () : base (IntPtr.Zero) {
 
54
                public Player (Playlist playlist) : base (IntPtr.Zero) {
 
55
                        this.playlist = playlist; 
 
56
                        playlist.SongReady += new Playlist.SongReadyHandler (OnSongReady);
 
57
 
47
58
                        Raw = player_new ();
48
59
                        playing = false;
49
60
                        new_song_cb = new SignalUtils.SignalDelegate (OnNewSong);
 
61
                        end_song_cb = new SignalUtils.SignalDelegate (OnEndSong);
 
62
                        error_cb = new SignalUtils.SignalDelegateStr (OnError);
50
63
                        SignalUtils.SignalConnect (Raw, "new-song", new_song_cb);
 
64
                        SignalUtils.SignalConnect (Raw, "end-song", end_song_cb);
 
65
                        SignalUtils.SignalConnect (Raw, "error", error_cb);
51
66
                }
52
67
 
53
68
                ~Player () {
75
90
                private static extern void player_play (IntPtr player);
76
91
                
77
92
                public void Play () {
 
93
                        Console.WriteLine ("Player: Requesting Song");
 
94
                        playing = true;
 
95
                        playlist.RequestNextSong ();                    
 
96
                        Driver.PlayerWindow.UpdatePlayingUI ();
 
97
                }
 
98
                
 
99
                private void OnSongReady (Song song)
 
100
                {
 
101
                        Console.WriteLine ("Player: Got Song");
 
102
                        current_song = song;
 
103
                        Console.WriteLine ("Now playing: " + song.Location);
 
104
                        Driver.connection.InvokeMetadataLoaded (song);
 
105
                        this.Location = song.Location;
78
106
                        player_play (Raw);
79
 
                        playing = true;
80
 
                        Driver.PlayerWindow.UpdatePlayingUI ();
 
107
                        
 
108
                        song.StartTime = DateTime.UtcNow;
81
109
                }
82
110
                
83
111
                [DllImport ("liblastexit")]
98
126
                
99
127
                private void OnNewSong (IntPtr obj) {
100
128
                        if (NewSong != null) {
101
 
                                NewSong ();
 
129
                                NewSong (current_song);
 
130
                        }
 
131
                }
 
132
 
 
133
                private void OnEndSong (IntPtr obj) {
 
134
                        Console.WriteLine ("EndSong");
 
135
                        
 
136
                        if (SongEnded != null) {
 
137
                                SongEnded (current_song);
 
138
                        }
 
139
                        current_song = null;
 
140
                        this.Play ();
 
141
                }
 
142
 
 
143
                private void OnError (IntPtr obj, string error) {
 
144
                        Console.Error.WriteLine ("GST error: " + error);
 
145
                        this.Stop ();
 
146
                }
 
147
 
 
148
                public void SkipSong ()
 
149
                {
 
150
                        if (Playing) {
 
151
                                player_stop (Raw);
 
152
                                Play ();
 
153
                        }                               
 
154
                }
 
155
                
 
156
                
 
157
                [DllImport ("liblastexit")]
 
158
                private static extern long player_get_stream_position (IntPtr player);
 
159
                
 
160
                public long StreamPosition {
 
161
                        get {
 
162
                                if (Playing) {
 
163
                                        return player_get_stream_position (Raw);
 
164
                                } else {
 
165
                                        return -1;
 
166
                                }
102
167
                        }
103
168
                }
104
169
        }