~ubuntu-branches/ubuntu/natty/exaile/natty

« back to all changes in this revision

Viewing changes to xl/player.py

  • Committer: Bazaar Package Importer
  • Author(s): Nick Ellery
  • Date: 2008-11-04 18:33:00 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20081104183300-e4t9seztl35bdb24
Tags: 0.2.14-0ubuntu1
* New upstream release (LP: #280287)
* debian/control:
  - tighten dependency on python-gtk2 to (>= 2.10)
  - added python-sexy to recommends to add a clear button to filters
  - added python-gnome2-extras to recommends for lyrics, better tray icon,
    etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import thread
21
21
from gettext import gettext as _
22
22
from xl import xlmisc, common, media, library, logger
23
 
from xl.gui import playlist as playlistgui
 
23
from xl.gui import playlist as playlistgui, information
24
24
import xl.path
25
25
 
26
26
class Player(gobject.GObject):
94
94
        elif message.type == gst.MESSAGE_EOS and not self.is_paused() \
95
95
            and self.eof_func:
96
96
            self.eof_func()
 
97
        elif message.type == gst.MESSAGE_ERROR:
 
98
            print message, dir(message)
97
99
 
98
100
        return True
99
101
 
 
102
    def __notify_source(self, o, s, num):
 
103
        s = self.playbin.get_property('source')
 
104
        s.set_property('device', num)
 
105
        self.playbin.disconnect(self.notify_id)
 
106
 
100
107
    def play(self, uri):
101
108
        """
102
109
            Plays the specified uri
116
123
                    raise Exception('File does not exist: ' + uri)
117
124
                uri = 'file://%s' % uri # FIXME: Wrong.
118
125
            uri = uri.replace('%', '%25')
 
126
 
 
127
            # for audio cds
 
128
            if uri.startswith("cdda://"):
 
129
                num = uri[uri.find('#') + 1:]
 
130
                uri = uri[:uri.find('#')]
 
131
                self.notify_id = self.playbin.connect('notify::source',
 
132
                    self.__notify_source, num)
 
133
 
119
134
            self.playbin.set_property('uri', uri.encode(xlmisc.get_default_encoding()))
120
135
 
121
 
        formats = {
122
 
            'mp3':  'mad',
123
 
            'flac': 'flac',
124
 
            'ogg':  'vorbis',
125
 
            'mpc':  'musepack',
126
 
            'tta':  'tta',
127
 
            'mp4':  'faad',
128
 
            'm4a':  'faad',
129
 
        }
130
 
 
131
 
        ext_re = re.compile(r'\.([^\.]*)$')
132
 
        m = ext_re.search(uri.encode(xlmisc.get_default_encoding()).lower())
133
 
        if m:
134
 
            ext = m.group(1)
135
 
        else:
136
 
            ext = ''
137
 
 
138
 
        if ext in formats.keys():
139
 
            plugin = formats[ext]
140
 
            if not gst.registry_get_default().find_plugin(plugin):
141
 
                raise Exception(_("You do not have the "
142
 
                    "appropriate Gstreamer plugin installed to play "
143
 
                    "this file: %(uri)s") % {'uri': uri})
144
 
 
145
136
        self.playbin.set_state(gst.STATE_PLAYING)
146
137
 
147
138
    def on_sync_message(self, bus, message):
536
527
            play_loc = track.loc
537
528
            if track.type == 'podcast' and track.download_path:
538
529
                play_loc = track.download_path
 
530
 
 
531
            # custom track setup
 
532
            if hasattr(track, 'start_play'):
 
533
                track.start_play()
 
534
 
539
535
            GSTPlayer.play(self, play_loc)
540
536
        except Exception, e:
541
537
            logger.log_exception()
550
546
 
551
547
        self.current = track
552
548
        self.exaile.update_track_information()
553
 
        track.submitted = False
554
549
 
555
550
        self.emit('play-track', track)
556
551
 
 
552
        # update information tab if it's open and set to do so
 
553
        if self.exaile.settings.get_boolean('ui/information_autoswitch',
 
554
            False):
 
555
            information.update_info(self.exaile.playlists_nb, track)
 
556
 
557
557
        artist_id = library.get_column_id(self.exaile.db, 'artists', 'name', track.artist)
558
558
        library.get_album_id(self.exaile.db, artist_id, track.album)
559
559
 
730
730
    
731
731
    @staticmethod
732
732
    def is_enabled(exaileplayer):
733
 
        return not exaileplayer.exaile.settings.get_boolean('replaygain/disabled', False)
 
733
        return exaileplayer.exaile.settings.get_boolean('replaygain/enabled', True)
734
734
    
735
735
    @staticmethod
736
736
    def get_elements(exaileplayer):