예제 #1
0
        # draw the text and timestamp on the frame
        ts = timestamp.strftime("%A %d %B %Y %I:%M:%S%p")
        cv2.putText(resizedGray, "Status: {}".format(text), (10, 20),
                cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
  

        print(text)
        if text == "Possible object":
                print("Searching for matching audio!")
                url = server.search(crop_img)
                print(url)
                cv2.putText(resizedGray, "Response: {}".format(url), (10, 40),
                cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
                if url != "nothingfound" and url != currentUrl:                        
                        mp.play(url)
                        currentUrl = url

        if text == "No object":
                mp.stop()
                currentUrl = ""
                   
               
        pingCounter += 1
        if pingCounter > 20:
                mp.ping()
                pingCounter = 0
      

        # check to see if the room is occupied
        if text == "Motion":
예제 #2
0
class PiPlayer:
    def __init__(self, configFile: str):
        self.config = loadConfig(configFile)
        self.player = MusicPlayer()
        self.database = MusicDatabase(self.config['database'])
        self.playlist = Playlist()
        thread.start_new_thread(self.primaryThread, ())

    def connect(self, *, initialize: bool = False):
        self.database.connect(initialize=initialize)

    def disconnect(self):
        self.database.disconnect()

    def playTest(self):
        pass

    def scanLibrary(self):
        def scanDirectory(self, directory: str, recursive: bool = False):
            for path in listdir(directory):
                fullPath = join(directory, path)
                if isdir(fullPath):
                    if recursive:
                        scanDirectory(self, fullPath, recursive)
                else:
                    try:
                        meta = MusicMetadata()
                        meta.loadFile(fullPath)
                        results = self.database.fetchMusicRowResults(
                            'file', fullPath)
                        shouldAdd = results is None or results.count < 1
                        self.database.addMusic(meta, update=not shouldAdd)
                    except:
                        pass

        for directory in self.config['directories']:
            directoryPath = abspath(directory['path'])
            recursive = directory['recursive']
            scanDirectory(self, directoryPath, recursive)

    def primaryThread(self):
        while (self.playlist.state == PlaylistState.Uninitialized):
            sleep(1)
        self.playSong(self.playlist.currentSong())
        self.playlist.state = PlaylistState.Playing
        self.playlist.next()
        while (self.playlist.state != PlaylistState.End):
            if (self.player.state == MusicPlayerState.Ended):
                self.playSong(self.playlist.currentSong())
                self.playlist.next()
            sleep(1)

    def playSong(self, song: MusicMetadata):
        self.player.load(song.file)
        print("Now playing")
        print(song.title)
        print("By " + song.artist)
        print(song.album)
        self.player.play()

    def loadPlaylist(self, playlistName: str):
        try:
            self.playlist.load(self.database.fetchPlaylist(playlistName))
        except:
            pass