#! /usr/bin/python '''These are core Ocarina system calls that should help in both development of future Ocarina features and in usage of ocarina-core''' __author__="bjschuma" __date__ ="$Mar 30, 2010 11:24:43 PM$" import ocarina from ct import message from ct import times from ct import path def load(path): '''Load the song located at path''' import gstreamer gstreamer.load(path) def seek(prcnt): ''' Seek to prcnt% of the song. If 0 < prcnt < 1, then we will seek to (prcnt * 100)% of song's duration. If prcnt < 100, then we will seek to prcnt% of the song's duration.''' import gstreamer good = gstreamer.seek(prcnt) if good == -1: message.write("There was an error seeking to: "+str(prcnt)) def progress(): '''Return the fraction of the song that we have already played''' import gstreamer progress = gstreamer.getProgress() message.write(progress) return progress def duration(): '''Return the total duration of the song. If message printing is enabled, then we will also print out string representing the duration in hh:mm:ss form''' import gstreamer duration = gstreamer.duration() message.write(times.ms2str(duration)) return duration def time(): '''Returns how far into the song gstreamer currently is. If message printing is enabled, then we will also print out a string representing the duration in hh:mm:ss form''' import gstreamer time = gstreamer.currentpos() message.write(times.ms2str(time)) return time def gsstate(): '''Returns the current gstreamer state''' import gstreamer state = gstreamer.getstate() message.write(state) return state def play(): '''Begin playback of the loaded song''' ocarina.events.start("ocarina-play") def pause(): '''Pause playback of the current song''' ocarina.events.start("ocarina-pause") def stop(): '''Pause playback of the current song and seek to the beginning''' pause() seek(0) def pyfile(file): '''If file exists, try to execute it as a python script''' if path.exists(file) == True: message.write("Running script: "+file,1) execfile(file)