Changeset 1619

Show
Ignore:
Timestamp:
2005-11-09 11:19:28 (3 years ago)
Author:
jkivlighn
Message:

Error handling when no file has been loaded and when there are errors in playlist saving/loading.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • annoamp/trunk/annoamp.py

    r1618 r1619  
    3939    global playlist_view 
    4040 
    41     #use the first file if nothing is already selected 
    42     if player.current == -1: 
    43         treemodel = playlist_view.get_model() 
    44         player.switch_source( treemodel.get_value(treemodel.get_iter_first(),0), 0 ) 
    45     player.play(); 
     41    if len(player.chapter_info) != 0: 
     42        #use the first file if nothing is already selected 
     43        if player.current == -1: 
     44            treemodel = playlist_view.get_model() 
     45            player.switch_source( treemodel.get_value(treemodel.get_iter_first(),0), 0 ) 
     46        player.play(); 
    4647     
    4748def pause(widget): 
  • annoamp/trunk/anxplayer.py

    r1615 r1619  
    173173    def play(self): 
    174174        print "Play." 
     175        if self.current == -1: 
     176            return 
     177 
    175178        result = self.bin.set_state(gst.STATE_PLAYING) 
    176179        self.bin.get_state() #block until the state is really changed 
     
    181184    def pause(self): 
    182185        print "Pause." 
     186        if self.current == -1: 
     187            return 
     188 
    183189        result = self.bin.set_state(gst.STATE_PAUSED) 
    184190        self.bin.get_state() #block until the state is really changed 
    185191         
    186192    def seek(self,location): 
     193        if self.current == -1: 
     194            return 
     195 
    187196        event = gst.event_new_seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, gst.SECOND*location, gst.SEEK_TYPE_NONE, 0); 
    188197        print "%s" % event 
     
    203212         
    204213    def next(self): 
    205         if self.pos == len(self.chapter_info[self.current])-1: 
     214        if self.current == -1 or self.pos == len(self.chapter_info[self.current])-1: 
    206215            print "Error in next()." 
    207216            return 
     
    224233    # These will differ when the stream is between clips. 
    225234    def chapter_at(self,location): 
     235        if self.current == -1: 
     236             return (-1,-1) 
     237 
    226238        chapter_end_at = -1 
    227239        for i in range(0,len(self.chapter_info[self.current])): 
  • annoamp/trunk/m3uhandler.py

    r1618 r1619  
    1818 
    1919def load_m3u( filename ): 
     20    try: 
     21        handle = file(filename, 'r') 
     22    except: 
     23        print "Unable to open",filename,"for reading" 
     24        return 
     25 
    2026    playlist = [] 
    21      
    2227    counter = 0 
    23     handle = file(filename) 
    2428    for line in handle: 
    2529        if line == "#EXTM3U\n": 
     
    4044 
    4145def save_m3u( filename, playlist ): 
    42     #TODO: do error checking 
    43     handle = open(filename, 'w') 
     46    try: 
     47        handle = file(filename, 'w') 
     48    except: 
     49        print "Unable to open",filename,"for writing" 
     50        return 
     51 
    4452    handle.write('#EXTM3U\n') 
    45     for file in playlist: 
    46         handle.write("#EXTINF:0,"+file+'\n') 
    47         handle.write(file+'\n') 
     53    for filename in playlist: 
     54        handle.write("#EXTINF:0,"+filename+'\n') 
     55        handle.write(filename+'\n')