Giter Site home page Giter Site logo

pybass3's Introduction

PyBASS wrapper

Downloads

LICENSING

The PyBass PYTHON wrapper is licensed under the MIT license. Meanwhile the BASS C Library is dual licensed as free to use for non-commercial development but requires a license for paid/commercial work. Please see http://un4seen.com

BASS library documentation

http://www.un4seen.com/doc/

Purpose and notes

A simple wrapper around un4seen.com's BASS audio library to enable playing various format media files from python.

Stock python usage

from argparse import ArgumentParser

from pybass3 import Song
import time

def main(song_file):
    song = Song(song_file)
    song.play()
    len_bytes = song.duration_bytes
    position_bytes = song.position_bytes
    print("Playing: ", song_file)
    print(f"Bytes: {len_bytes=}")

    while position_bytes < len_bytes:
        print(song.position, song.duration)
        time.sleep(1)


if __name__ == "__main__":
    parser = ArgumentParser()
    parser.add_argument("song_file")
    args = parser.parse_args()

    main(args.song_file)

Windows playlist example

import pathlib
import time
import argparse
import msvcrt

from pybass3 import Song
from pybass3.playlist import Playlist




def kbfunc():
    x = msvcrt.kbhit()
    if x:
       ret = ord(msvcrt.getch())
    else:
       ret = 0

    return ret


def main(dir_path):
    dir_path = pathlib.Path(dir_path)

    playlist = Playlist()
    playlist.add_directory(dir_path, recurse=True)

    playlist.play()
    play_indefinitely = True
    while play_indefinitely:
        try:
            print(playlist.current.file_path.name, playlist.current.position, playlist.current.duration)
            playlist.tick()
            key = kbfunc()
            if key:                
                if key == 122: # Z
                    print("Previous")
                    playlist.previous()
                elif key == 98: # B                    
                    print("Next")
                    playlist.next()
                elif key == 120: # X
                    print("Play")
                    playlist.play()
                elif key == 99: # c
                    print("Pause")    
                    playlist.pause()
                elif key == 118: # v
                    print("Stop")
                    playlist.stop()
            else:
                time.sleep(1)
                
        except KeyboardInterrupt:
            playlist.free()
            play_indefinitely = False


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("song_dir")
    args = parser.parse_args()

    main(args.song_dir)

pybass3's People

Contributors

devdave avatar kaens avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.