コード例 #1
0
def load_file(track, filesystem_monitor: FilesystemMonitor, offline_cache: OfflineCache):
    """
    Loads a given track into the player.
    :param track: track to be loaded
    """
    global __current_track
    global __player

    if get_gst_player_state() == Gst.State.PLAYING:
        save_current_track_position()
        save_current_book_position(__current_track)

    __current_track = track
    emit_event("stop")
    __player.set_state(Gst.State.NULL)

    init()

    if filesystem_monitor.is_track_online(track):
        path = track.file
    else:
        path = offline_cache.get_cached_path(track)
        if not path:
            path = track.file
    __player.set_property("uri", "file://" + path)
    __player.set_state(Gst.State.PAUSED)
    save_current_book_position(__current_track)
    Settings.update(last_played_book=__current_track.book).execute()
    Book.update(last_played=int(time.time())).where(
        Book.id == __current_track.book.id).execute()
    jump_to_ns(track.position)
    emit_event("track-changed", track)
コード例 #2
0
def load_last_book(filesystem_monitor: FilesystemMonitor, offline_cache: OfflineCache):
    """
    Load the last played book into the player.
    """
    global __current_track
    global __player
    global __wait_to_seek

    last_book = Settings.get().last_played_book

    if last_book and last_book.position != 0:

        query = Track.select().where(Track.id == last_book.position)
        if query.exists():
            last_track = query.get()

            if last_track:
                __player.set_state(Gst.State.NULL)
                if filesystem_monitor.is_track_online(last_track):
                    path = last_track.file
                else:
                    path = offline_cache.get_cached_path(last_track)
                    if not path:
                        return
                __player.set_property("uri", "file://" + path)
                __wait_to_seek = True
                __player.set_state(Gst.State.PAUSED)
                __current_track = last_track

                Book.update(last_played=int(time.time())).where(
                    Book.id == last_book.id).execute()

                emit_event("track-changed", last_track)
コード例 #3
0
def __on_storage_changed(event, message, offline_cache: OfflineCache):
    """
    """
    global __player

    if event == "storage-offline":
        if get_current_track() and message in get_current_track().file:
            cached_path = offline_cache.get_cached_path(get_current_track())
            if not cached_path:
                stop()
                unload()
                emit_event("stop")