示例#1
0
def vol_dec():
    per=libvlc_audio_get_volume(player)
    per-=10
    if not per<=0:
        libvlc_audio_set_volume(player, per)
    else:
        pass
示例#2
0
def vol_in():
    per=libvlc_audio_get_volume(player)
    per+=10
    if not per>=100:
        libvlc_audio_set_volume(player, per)
    else:
        pass
示例#3
0
def play_stream(stream_url):
    global player
    global volume_thr
    global volume_thread_continue

    logger.info("Playing stream: " + stream_url)

    # Use python-vlc to create a media player
    player = vlc.MediaPlayer(stream_url)
    vlc.libvlc_audio_set_volume(player, 30)
    player.play()

    # Shutdown previous volume thread
    logger.info("Telling volume thread to stop")
    volume_thread_continue = False
    logger.info("Joining volume_thr thread")
    volume_thr.join()
    logger.info("Volume thread has finished. Starting a new one")

    # Start new volume thread
    volume_thread_continue = True
    volume_thr = threading.Thread(target=volume_thread,
                                  args=(volume_pot, player),
                                  daemon=True)
    volume_thr.start()
示例#4
0
def play_audio_tts(file):
    print("POntos de interesses: ", file)
    if type(file) is str:
        instance = vlc.Instance('--aout=alsa')
        p = instance.media_player_new()
        file = re.sub(r"\s+", '_', file)
        m = instance.media_new('/home/pi/Desktop/TCC/TCC-Furb/audios/' + file +
                               '.mp3')
        p.set_media(m)
        p.play()
        # p.pause()
        vlc.libvlc_audio_set_volume(p, 80)
        time.sleep(song_length(file))
    else:
        for i in file:
            for j in i:
                print("falando", j)
                j = re.sub(r"\s+", '_', j)
                instance = vlc.Instance('--aout=alsa')
                p = instance.media_player_new()
                m = instance.media_new(
                    '/home/pi/Desktop/TCC/TCC-Furb/audios/' + j + '.mp3')
                p.set_media(m)
                p.play()
                # p.pause()
                vlc.libvlc_audio_set_volume(p, 80)
                time.sleep(song_length(j))
示例#5
0
 def prevSong(self):
     item = self.getPrev()
     if (len(item) > 0):
         self.current -= 1
         media = self.instance.media_new(item[1])
         self.player.set_media(media)
         self.play()
         vlc.libvlc_audio_set_volume(self.player, self.volume)
         time.sleep(5)
示例#6
0
 def volume_up(self, prcnt=10):
     '''pump up the volume 10% by default'''
     logging.info(
         'Entered function in PlayListManager: volume_up(self,prcnt=10)')
     self.current_volume = vlc.libvlc_audio_get_volume(self.player)
     self.current_volume = self.current_volume + prcnt
     if self.current_volume > 100:
         self.current_volume = 100
     vlc.libvlc_audio_set_volume(self.player, self.current_volume)
     show_notification("Volume", str(self.current_volume))
示例#7
0
 def volume_down(self, prcnt=10):
     """turn the volume down 10% by default"""
     logging.info(
         'Entered function in PlayListManager: volume_down(self,prcnt=10)')
     self.current_volume = vlc.libvlc_audio_get_volume(self.player)
     self.current_volume = self.current_volume - prcnt
     if self.current_volume < 0:
         self.current_volume = 0
     vlc.libvlc_audio_set_volume(self.player, self.current_volume)
     show_notification("Volume", str(self.current_volume))
示例#8
0
 def add(self, item):
     if (len(self.playlist) == 0):
         self.playlist.append(item)
         media = self.instance.media_new(item[1])
         self.player.set_media(media)
         self.player.play()
         vlc.libvlc_audio_set_volume(self.player, self.volume)
         time.sleep(5)
     else:
         self.playlist.append(item)
示例#9
0
 def __init__(self,
              mp3_filename,
              filepath_prefix=os.path.expanduser("~/Music")):
     mp3_filepath = os.path.join(filepath_prefix, mp3_filename)
     self.mp3_name = mp3_filename
     self.mp3_player = vlc.MediaPlayer(mp3_filepath)
     self.play()
     vlc.libvlc_audio_set_volume(self.mp3_player, 0)
     time.sleep(1)
     self.len = vlc.libvlc_media_player_get_length(self.mp3_player)
     self.stop()
示例#10
0
def play_sound(filename):
    """
    Play sound with vlc player.
    """
    instance = vlc.Instance("--aout=alsa")
    p = instance.media_player_new()
    m = instance.media_new(filename)
    p.set_media(m)
    p.play()
    p.pause()
    vlc.libvlc_audio_set_volume(p, 100)
示例#11
0
    def play(self, url):

        playurl, length, title, author = self._PlayUrl(url)

        Media = self.Instance.media_new(playurl)
        Media.get_mrl()
        self.player.set_media(Media)

        print('Playing\n' + title)
        self._notify('YouTube Radio', title + '\nby ' + author)
        self.player.play()
        vlc.libvlc_audio_set_volume(self.player, self.volume)
        time.sleep(length)
示例#12
0
def play_radio_2():
    global player_is_playing
    global player

    if player_is_playing:
        player.stop()
        player_is_playing = False

    print("Playing BBC Radio 2")
    player = vlc.MediaPlayer(
        "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p")
    vlc.libvlc_audio_set_volume(player, 30)
    player_is_playing = True
    player.play()
示例#13
0
def shutdown():
    logger.info("Shutting down")
    stop_stream()

    say("Shutting down now")

    player = vlc.MediaPlayer("/home/pi/roberts-radio/media/shutdown.mp3")
    # Nice and lound
    vlc.libvlc_audio_set_volume(player, 80)
    player.play()
    sleep(3)

    # Shutdown the Raspberry Pi and exit nicely
    subprocess.call(["sudo", "halt"])
    exit(0)
 def initialize(self, url):
     # TODO: modify the title in the media player title bar to "Computer Vision Media Controller" or it
     #  may be cool to extract data from the actual video to make the title dynamic
     if not self.validate_url(url):
         return False
     media = self.vlc_instance.media_new(url)
     media_list = self.vlc_instance.media_list_new([url])
     self.player.set_media(media)
     list_player = self.vlc_instance.media_list_player_new()
     list_player.set_media_player(self.player)
     list_player.set_media_list(media_list)
     list_player.play()
     vlc.libvlc_audio_set_volume(self.player, self.volume)
     print("player initialized")
     return True
示例#15
0
def play_offline(name):
    global browser
    global player
    if browser:
        browser.close()
        browser = None
    if player:
        player.stop()
        player = None
    print name
    if name:
        player = vlc.MediaPlayer(library + name)
        vlc.libvlc_audio_set_volume(player, 85)
        player.play()
    return json.dumps({'done': True, 'offline': True})
 def initialize(self, url):
     # TODO: modify the title in the media player title bar to
     #  "Computer Vision Media Controller"
     if not self._validate_url(url):
         return False
     media = self.vlc_instance.media_new(url)
     media_list = self.vlc_instance.media_list_new([url])
     self.player.set_media(media)
     list_player = self.vlc_instance.media_list_player_new()
     list_player.set_media_player(self.player)
     list_player.set_media_list(media_list)
     list_player.play()
     vlc.libvlc_audio_set_volume(self.player, self.volume)
     print("player initialized")
     return True
示例#17
0
def volume_thread(pot, player):
    global volume_thread_continue

    logger.debug("Started volume thread")

    # Default volume setting
    volume_setting = 30
    vlc.libvlc_audio_set_volume(player, volume_setting)

    # Keep re-setting the volume according to pot value unless you haven't moved the dial
    while volume_thread_continue:
        last_volume_setting = volume_setting

        volume_setting = get_abs_from_pot(pot)

        if volume_setting != last_volume_setting:
            logger.debug("Setting volume to " + str(volume_setting))
            vlc.libvlc_audio_set_volume(player, volume_setting)

        # Shutdown control section
        # If volume is 0 and remains so for 5 seconds, shutdown with a countdown
        if volume_setting == 0:
            shutdown_setting = True
            shutdown_counter = 5
            set_sys_volume()

            say("Shut down requested")

            while shutdown_setting:
                volume_setting = get_abs_from_pot(pot)

                # If volume changes, abort the shutdown sequence
                if volume_setting != 0:
                    say("Shut down aborted")
                    shutdown_setting = False
                else:
                    say(str(shutdown_counter))
                    shutdown_counter = shutdown_counter - 1

                    # If you've reached zero, shutdown the radio
                    if shutdown_counter == 0:
                        shutdown()

        # Don't overload the Pi by infinite loop with no delay
        sleep(0.3)

    logger.info("Finishing volume thread")
示例#18
0
    def intent_1_callback(self, hermes, intent_message):
        # terminate the session first if not continue
        hermes.publish_end_session(intent_message.session_id, "")

        # action code goes here...
        print('[Received] intent: {}'.format(
            intent_message.intent.intent_name))
        songname = str(intent_message.slots.songName)
        snipssongname = intent_message.slots.songName
        # if need to speak the execution result by tts
        ## hermes.publish_start_session_notification(intent_message.site_id, songname[0].raw_value, "")
        #hermes.publish_start_session_notification(intent_message.site_id, "Action1 has been done", "")

        try:
            dbfunks.dbConnect()
            song = dbfunks.getSong(snipssongname[0].raw_value)
            songPath = song[1]
            print("song is " + song[1])
            #instance = vlc.Instance('--aout=alsa')
            #p = instance.media_player_new()
            m = instance.media_new_path(songPath)
            p.set_media(m)
            hermes.publish_continue_session(intent_message.site_id, " ", "")
            p.play()
            print(p.get_state())
            print(p.get_length())
            time.sleep(1.5)
            duration = p.get_length() / 1000
            time.sleep(duration)
            vlc.libvlc_audio_set_volume(p, 0)  # volume 0..100
            print(p.get_state())
            vlcstate = p.get_state()
            print("VLC released")
            quit()
            #hermes.publish_start_session_notification(intent_message.site_id," ", "")

        except Exception as e:
            hermes.publish_start_session_notification(
                intent_message.site_id, snipssongname[0].raw_value, "")
            #hermes.publish_start_session_notification(intent_message.site_id, e, "")
            print("Error: " + str(e))

        finally:
            hermes.publish_start_session_notification(intent_message.site_id,
                                                      "Action finished", "")
示例#19
0
 def _call_vlc(self, audio_file: PathLike):
     """
     """
     try:
         # import needs libs and can can crash appplication
         import vlc  # pylint: disable=import-outside-toplevel
         player: vlc.MediaPlayer = vlc.MediaPlayer(str(audio_file))
         vlc.libvlc_audio_set_volume(
             player, 140)  # make it louder for passive loudspeake
         if self._comps and self._comps.energy_saver.night_mode_active:  # lower volume at night
             player.audio_set_volume(50)
         with self.lock:  # wait for previous sound to end
             player.play()
             time.sleep(2)  # wait for starting
             while player.is_playing():
                 time.sleep(1)
     except Exception as error:
         self._logger.warning("Sound: Cannot play sound: %s", str(error))
def isr23(channel):
    if GPIO.input(23) == 0:
        print("23=0")
    else:
        print("ISR23")
        Player.pause()
        JinglePlayer.set_media(JingleMedia)
        vlc.libvlc_audio_set_volume(JinglePlayer, 90)
        JinglePlayer.play()
        JinglePlaying = set([1])
        JingleTimeLeft = True
        while JingleTimeLeft == True:
            print("ISR23 Jingle Player Timepos", JinglePlayer.get_position())
            JingleTime = JinglePlayer.get_state()
            if JingleTime not in JinglePlaying:
                JingleTimeLeft = False
                print(JingleTime)
            time.sleep(1)
        JingleDuration = JinglePlayer.get_length() / 1000
        time.sleep(JingleDuration)
        vlc.libvlc_audio_set_volume(JinglePlayer, 0)
        JinglePlayer.stop()
        MusicPlayer()
示例#21
0
 def handleVolume(self, phoneNumber, vol):
     if phoneNumber == u'+15108470608':
         vlc.libvlc_audio_set_volume(self.mediaPlayer, vol)
示例#22
0
    def set_volume(self, volume):
        vlc.libvlc_audio_set_volume(self.player, volume)  # volume 0..100

        
示例#23
0
def set_volume(value):
    global media_list_player
    if media_list_player:
        vlc.libvlc_audio_set_volume(media_list_player.get_media_player(),
                                    value)
示例#24
0
 def setVolume(self, volume):
     self.volume += int(volume)
     vlc.libvlc_audio_set_volume(self.player, self.volume)
示例#25
0
    try:
        index=0
        onlyfiles=[""]
        file_dir=filedialog.askdirectory()
        player.stop()
        onlyfiles = [f for f in listdir(file_dir) if f.endswith('.mp3')]
        if(onlyfiles==[]): # if no mp3 files in directory
            raise FileNotFoundError
        start()
    except(FileNotFoundError):
        if(file_dir==""):
            pass
        else:
            messagebox.showinfo('Error','No MP3 in selected folder select a folder with mp3 file')
player=MediaPlayer()
libvlc_audio_set_volume(player,70)
def start():
    global index
    global player
    global playing
    global first_time
    global flag
    try:
        song_name=onlyfiles[index].replace(".mp3","")
        label.configure(text=song_name)
        player=MediaPlayer(join(file_dir,onlyfiles[index]))
        player.play()
        time.sleep(1)
        playing = True
        first_time = False
        button2.configure(image=pausePh)
def MusicPlayer():
    #Player.set_media(Media)
    JinglePlayer.stop()
    Player.play()
    vlc.libvlc_audio_set_volume(Player, 90)
示例#27
0
 def set_volume(self, volume):
     '''set the volume to a specified level no sanity checks'''
     logging.info('Entered function in PlayListManager: set_volume(self)')
     vlc.libvlc_audio_set_volume(self.player, volume)
示例#28
0
def data(slide):
    global player
    vlc.libvlc_audio_set_volume(player, slide+1)
示例#29
0
button1_up = Button(4)
button1_down = Button(17)

button2_up = Button(27)
button2_down = Button(22)

button3_up = Button(5)
button3_down = Button(6)

button4_up = Button(13)
button4_down = Button(19)

# Play something gentle to start with, just in case it goes wrong, at least it's short!
player = vlc.MediaPlayer("/home/pi/roberts-radio/media/guitar.mp3")
player_is_playing = True
vlc.libvlc_audio_set_volume(player, 30)

exit(0)


def play_radio_2():
    global player_is_playing
    global player

    if player_is_playing:
        player.stop()
        player_is_playing = False

    print("Playing BBC Radio 2")
    player = vlc.MediaPlayer(
        "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p")
示例#30
0
def keyboardLogic(loop):
    i = input("> ")
    if i == "test":
        print("Input detected")
    elif i == "status":
        print("当前人气值: " + str(lastPopularity))
    elif i == "debug":
        print("inStandByMode:" + str(inStandByMode))
        print("songIndex:" + str(songIndex))
        print("standbyIndex:" + str(standbyIndex))
        print("player status: " + str(mediaPlayer.get_status()))
    elif i == "pause":
        mediaPlayer.pause()
    elif i == "play":
        mediaPlayer.play()
    elif i == "stop":
        mediaPlayer.stop()
    elif i == "next":
        if songIndex >= len(songList):
            mediaPlayer.stop()
            print("This is the last song")
        else:
            setSong(songIndex)
    elif i == "list" or i == "ls":
        showRemainingSongList(songList)
    elif i == "full list":
        showFullSongList(songList)
    elif i[0:8] == "standby ":
        if i[8:12] == "add ":
            searchTask = asyncio.ensure_future(searchSong(i[12:]))
            loop.run_until_complete(searchTask)
            song = searchTask.result()
            if song:
                addingTask = asyncio.ensure_future(
                    addToList(song, standbyList, 1))
                loop.run_until_complete(addingTask)
            else:
                print("Cannot add to standby list: Song not found")
        elif i[8:] == "list" or i[8:] == "ls":
            showRemainingSongList(standbyList, standbyIndex)
        elif i[8:] == "full list":
            showFullSongList(standbyList, standbyIndex)
        elif i[8:] == "next":
            mediaPlayer.stop()
        elif i[8:15] == "remove ":
            try:
                songToBeRemoved = int(i[15:]) - 1  #从1开始数
                standbyList.pop(songToBeRemoved)
            except:
                print("Error: invalid arguments")
        elif i[8:15] == "import ":
            try:
                importFromFile(i[15:])
            except:
                print("Import error: invalid file " + i[15:])
        else:
            print("Error: command not found")

    elif i[0:5] == "swap " and i[6] == " ":
        try:
            swap1 = int(i[7]) - 1  #从1开始数
            swap2 = int(i[5]) - 1
            if swap1 <= len(songList) and swap2 <= len(songList):
                tmp = songList[swap1]
                songList[swap1] = songList[swap2]
                songList[swap2] = tmp
            else:
                print("swap Error: Out of range")
        except:
            print("Error: invalid arguments")

    elif i == "clear":
        os.system("clear")  #macOS, linux
    elif i == "cls":
        os.system("cls")  #Windows
    elif i == "help":
        printHelp()
    elif i == "version" or i == "v":
        print(version + " " + versionStatus + " build " + str(build))
    elif i == "":
        print(" ")
    elif i[0:7] == "remove ":
        try:
            songToBeRemoved = int(i[7:]) - 1  #从1开始数
            songList.pop(songToBeRemoved)
        except:
            print("Error: invalid arguments")
    elif i == "quit" or i == "exit":
        print("     Highest popularity: " + str(highestPopularity))
        print("     Total income: " + str(income))
        print("     Quitting, Good bye")
        os._exit(0)
    elif i[0:3] == "say":
        ttsProcess = Process(target=text2SpeechProcess, args=(i[4:], ))
        ttsProcess.start()
    elif i[0:10] == "set volome":
        volumeIsSet = vlc.libvlc_audio_set_volume(mediaPlayer, i[10:])
        if volumeIsSet == -1:
            print("Error: Volume out of range")
        else:
            print("Volume set " + i[10:] + "%")
        #endif
    elif i[0:7] == "set vol":
        volumeIsSet = vlc.libvlc_audio_set_volume(mediaPlayer, i[7:])
        if volumeIsSet == -1:
            print("Error: Volume out of range")
        else:
            print("Volume set " + i[7:] + "%")
        #endif
    else:
        print("Error: command not found")