class VLC:
    def __init__(self):
        self.Player = Instance('--loop')

    def addPlaylist(self):
        self.mediaList = self.Player.media_list_new()
        path = "/Users/avni_aaron/Desktop/Classical_music"
        songs = os.listdir(path)
        for s in songs:
            self.mediaList.add_media(
                self.Player.media_new(os.path.join(path, s)))
        self.listPlayer = self.Player.media_list_player_new()
        self.listPlayer.set_media_list(self.mediaList)

    def play(self):
        self.listPlayer.play()

    def next(self):
        self.listPlayer.next()

    def pause(self):
        self.listPlayer.pause()

    def previous(self):
        self.listPlayer.previous()

    def stop(self):
        self.listPlayer.stop()

    def set_volume(self, vol):
        self.listPlayer.audio_set_volume(vol)
class VLC:  # Crea instancia de VLC
    def __init__(self):
        self.Player = Instance('--loop')  #lo genera en modo bucle

    def addPlaylist(
            self, op
    ):  #agrega a la lista de reproduccion dependiendo el tipo de archivo
        self.mediaList = self.Player.media_list_new(
        )  #crea lista de reproduccion vacia

        path = r"/home/pi/Desktop/PFE"
        songs = os.listdir(path)  #crea lista de los archivos
        #        for x in songs:
        #
        #              print(x)
        for s in songs:  #filtra tipo de archivo dependiendo la eleccion
            if op == 1:  #fotos
                if '.jpg' in str(s) or 'png' in str(s) or 'jpeg' in str(s):
                    self.mediaList.add_media(
                        self.Player.media_new(os.path.join(path, s)))

            if op == 2:  #videos
                if '.mp4' in str(s) or '.avi' in str(s):
                    self.mediaList.add_media(
                        self.Player.media_new(os.path.join(path, s)))

            if op == 3:  #musica
                if '.mp3' in str(s):
                    self.mediaList.add_media(
                        self.Player.media_new(os.path.join(path, s)))
        self.listPlayer = self.Player.media_list_player_new(
        )  #crea lista de reproduccion vacia en la instancia de VLC
        self.listPlayer.set_media_list(
            self.mediaList
        )  #remplaza la lista de reproduccion de la instancia anterior con la nueva

    def play(self):  #reproduce
        self.listPlayer.play()

    def next(self):  #siguiente
        self.listPlayer.next()

    def pause(self):  #pausa
        self.listPlayer.pause()

    def previous(self):  #anterior
        self.listPlayer.previous()

    def stop(self):  #Alto
        self.listPlayer.stop()

    def playpause(self):  #itera entre reproducir y pausar
        if self.listPlayer.is_playing():
            self.stop()
        else:
            self.play()
Exemple #3
0
class Player:
    def __init__(self):
        self.Player = Instance('--loop --no-video')
        self.volume = 50
        self.listPlayer = None

    def setPlaylist(self, playlist):

        if self.listPlayer != None:
            self.listPlayer.stop()
            self.listPlayer.release()

        self.mediaList = self.Player.media_list_new()
        for song in playlist:
            self.mediaList.add_media(self.Player.media_new(song))
        self.listPlayer = self.Player.media_list_player_new()
        self.listPlayer.set_media_list(self.mediaList)
        self.listPlayer.get_media_player().audio_set_volume(self.volume)

    def play(self, index):
        self.listPlayer.play_item_at_index(index)

    def next(self):
        self.listPlayer.next()

    def pause(self):
        self.listPlayer.pause()

    def previous(self):
        self.listPlayer.previous()

    def stop(self):
        self.listPlayer.stop()

    def setPosition(self, v):
        self.listPlayer.get_media_player().set_position(v)

    def setVolume(self, v):
        self.volume = int(v * 100)
        if self.listPlayer != None:
            self.listPlayer.get_media_player().audio_set_volume(self.volume)

    def addToQueue(self, song):
        self.mediaList.add_media(self.Player.media_new(song))
Exemple #4
0
class testVLC:
    def __init__(self):
        self.list1 = playlist
        self.Player = Instance('--loop')

    def addPlaylist(self):
        self.mediaList = self.Player.media_list_new()
        for music in self.list1:
            self.mediaList.add_media(self.Player.media_new(music_dir+'/'+music))
        self.listPlayer = self.Player.media_list_player_new()
        self.listPlayer.set_media_list(self.mediaList)
    def playPlaylist(self):
        self.listPlayer.play()
    def nextPlay(self):
        self.listPlayer.next()
    def pausePlaylist(self):
        self.listPlayer.pause()
    def stopPlaylist(self):
        self.listPlayer.stop()
Exemple #5
0
class YoutubePLR:
    def __init__(self):
        self.Player = Instance('--loop')

    def Vplayer(self, url):
        url = str(url)
        video = pafy.new(url)
        messagebox.showinfo(
            "Notice", " Please Wait....  Seeking video may take some time")
        best = video.getbest()
        self.media_list = self.Player.media_list_new()
        self.media_player = self.Player.media_list_player_new()
        self.media = self.Player.media_new(best.url)
        self.media_list.add_media(self.media)
        self.media_player.set_media_list(self.media_list)
        self.media_player.play()
        time.sleep(15)

    def stopVideo(self):
        #media.stop()
        print("Stoping")
        self.media_player.stop()
        #sys.exit()

    def callSearch(self):
        messagebox.showinfo("Notice",
                            " Please Wait....  Searching may take some time.")
        videoName = str(self.video_Name.get())
        print(videoName)
        if videoName is not None:
            videosSearch = VideosSearch(str(videoName), limit=5)

            for i in range(5):
                self.titleList.append(
                    str(videosSearch.result()['result'][i]['title'][0:45]))
                self.linkList.append(
                    videosSearch.result()['result'][i]['link'])
            for i in range(5):
                print(self.titleList[i], "\t\t", self.linkList[i])
                #print(videosSearch.result()['result'][i]['title'][0:45])

            time.sleep(5)
            self.WidgetResult()
        else:
            print("Null Search")

    def Browse(self):
        download_Directory = filedialog.askdirectory(
            initialdir=pathlib.Path.cwd())
        self.download_Path.set(download_Directory)

    def Download(self, url):
        Youtube_link = str(url)
        print(Youtube_link)
        download_Folder = self.download_Path.get()
        print(download_Folder)
        if download_Folder == None or download_Folder == "":
            messagebox.showwarning("Choose Location",
                                   "Choose a valid location in browse option")
            return
        try:
            getVideo = pafy.new(Youtube_link)
            vidBest = getVideo.getbest()
            print(" Downloading -----", vidBest.resolution, vidBest.extension,
                  " .....Please Wait ")
            messagebox.showinfo(
                "Notice", " Please Wait....  Downloading may take some time")
            vidBest.download(download_Folder)
            messagebox.showinfo("Successfully",
                                "Downloaded and Saved in\n" + download_Folder)
        except:
            print("Connection Error")

    def Widgets(self):
        Label(self.root,
              text="Youtube Player and Downloader",
              font=("Gill Sans Ultra Bold Condensed", 30),
              bg="#000000",
              fg="#f9540b").grid(row=1, columnspan=3, padx=18)

        link_label = Label(self.root,
                           text="Search Video",
                           bg="#E8D579",
                           width=20)
        link_label.grid(row=3, column=0, pady=10, padx=10)

        linkText = Entry(self.root, width=40, textvariable=self.video_Name)
        linkText.insert(END, 'attention')
        linkText.grid(row=3, column=1, pady=10, padx=5)

        Search_B = Button(self.root,
                          text="Search",
                          command=self.callSearch,
                          width=15,
                          bg="#05E8E0")
        Search_B.grid(row=3, column=2, pady=10, padx=5)

    def WidgetResult(self):
        self.root.geometry("690x360")
        colrLab = "#cccccc"
        colrBut = "#fd9c35"
        #command= lambda: self.Vplayer(self.linkList[0])
        destination_label = Label(self.root,
                                  text="Destination",
                                  bg="#E8D579",
                                  width=20)
        destination_label.grid(row=4, column=0, pady=10, padx=10)

        destiText = Entry(self.root, width=40, textvariable=self.download_Path)
        destiText.insert(END, '')
        destiText.grid(row=4, column=1, pady=10, padx=5)

        browse_B = Button(self.root,
                          text="Browse",
                          command=self.Browse,
                          width=15,
                          bg="#05E8E0")
        browse_B.grid(row=4, column=2, pady=10, padx=5)

        # Search list

        resultLabel_1 = Label(self.root,
                              text=self.titleList[0],
                              bg=colrLab,
                              width=50)  #1
        resultLabel_1.grid(row=5, columnspan=2, pady=5, padx=5)

        Search_B_1 = Button(self.root,
                            text="Play",
                            command=lambda: self.Vplayer(self.linkList[0]),
                            width=10,
                            bg=colrBut)
        Search_B_1.grid(row=5, column=2, pady=1, padx=1)

        Download_B_1 = Button(self.root,
                              text="Download",
                              command=lambda: self.Download(self.linkList[0]),
                              width=10,
                              bg="#a2cf6e",
                              bd=1)
        Download_B_1.grid(row=5, column=3, pady=3, padx=3)

        resultLabel_2 = Label(self.root,
                              text=self.titleList[1],
                              bg=colrLab,
                              width=50)  #2
        resultLabel_2.grid(row=6, columnspan=2, pady=5, padx=5)

        Search_B_2 = Button(self.root,
                            text="Play",
                            command=lambda: self.Vplayer(self.linkList[1]),
                            width=10,
                            bg=colrBut)
        Search_B_2.grid(row=6, column=2, pady=1, padx=1)

        Download_B_2 = Button(self.root,
                              text="Download",
                              command=lambda: self.Download(self.linkList[1]),
                              width=10,
                              bg="#a2cf6e",
                              bd=1)
        Download_B_2.grid(row=6, column=3, pady=3, padx=3)

        resultLabel_3 = Label(self.root,
                              text=self.titleList[2],
                              bg=colrLab,
                              width=50)  #3
        resultLabel_3.grid(row=7, columnspan=2, pady=5, padx=5)

        Search_B_3 = Button(self.root,
                            text="Play",
                            command=lambda: self.Vplayer(self.linkList[2]),
                            width=10,
                            bg=colrBut)
        Search_B_3.grid(row=7, column=2, pady=1, padx=1)

        Download_B_3 = Button(self.root,
                              text="Download",
                              command=lambda: self.Download(self.linkList[2]),
                              width=10,
                              bg="#a2cf6e",
                              bd=1)
        Download_B_3.grid(row=7, column=3, pady=3, padx=3)

        resultLabel_4 = Label(self.root,
                              text=self.titleList[3],
                              bg=colrLab,
                              width=50)  #4
        resultLabel_4.grid(row=8, columnspan=2, pady=5, padx=5)

        Search_B_4 = Button(self.root,
                            text="Play",
                            command=lambda: self.Vplayer(self.linkList[3]),
                            width=10,
                            bg=colrBut)
        Search_B_4.grid(row=8, column=2, pady=1, padx=1)

        Download_B_4 = Button(self.root,
                              text="Download",
                              command=lambda: self.Download(self.linkList[3]),
                              width=10,
                              bg="#a2cf6e",
                              bd=1)
        Download_B_4.grid(row=8, column=3, pady=3, padx=3)

        resultLabel_5 = Label(self.root,
                              text=self.titleList[4],
                              bg=colrLab,
                              width=50)  #5
        resultLabel_5.grid(row=9, columnspan=2, pady=5, padx=5)

        Search_B_5 = Button(self.root,
                            text="Play",
                            command=lambda: self.Vplayer(self.linkList[4]),
                            width=10,
                            bg=colrBut)
        Search_B_5.grid(row=9, column=2, pady=1, padx=1)

        Download_B_5 = Button(self.root,
                              text="Download",
                              command=lambda: self.Download(self.linkList[4]),
                              width=10,
                              bg="#a2cf6e",
                              bd=1)
        Download_B_5.grid(row=9, column=3, pady=3, padx=3)

        Stop_B = Button(self.root,
                        text="Stop Video",
                        command=self.stopVideo,
                        width=20,
                        bg="#a2cf6e")
        Stop_B.grid(row=10, column=1, pady=8, padx=3)

        #Download_B=Button(self.root,text="Download",command=Download,width=20,bg="#a2cf6e",bd=1)
        #Download_B.grid(row=9,column=1,pady=3,padx=3)

    def Start(self):
        self.root = Tk()
        self.root.geometry("600x130")
        #self.root.resizable(0,0)
        self.root.title("Youtube Video Downloader")
        self.root.config(background="#000000")
        self.video_Name = StringVar()
        self.download_Path = StringVar()
        self.titleList = []
        self.linkList = []

        self.Widgets()
        self.root.mainloop()
Exemple #6
0
class Player(Tk.Frame):
    """The main window has to deal with events.
    """
    def __init__(self, parent, title=None):
        Tk.Frame.__init__(self, parent)
        self.Player = Instance('--loop')
        self.parent = parent

        #before new update

        #       q1="""SELECT `episode_table`.`episode_num`,
        #   `episode_table`.`episode_time`,
        #   `episode_table`.`episode_season`
        #FROM `personal_use`.`episode_table`;"""
        #        results = read_query(connection, q1)

        #       self.episode_num=results[0][0]-1  ##subracting 1 to match array position of real episode
        #       self.episode_season=results[0][2]
        #       self.episode_time=results[0][1]

        self.first_entrence = 0
        self.label_arr = []
        self.running = 0
        self.dirname = ""
        self.videos = []
        self.video_len = 0

        if title == None:
            title = "tk_vlc"
        self.parent.title(title)

        # Menu Bar
        #   File Menu
        menubar = Tk.Menu(self.parent)
        self.parent.config(menu=menubar)

        fileMenu = Tk.Menu(menubar)
        fileMenu.add_command(label="Open", underline=0, command=self.OnOpen)
        fileMenu.add_command(label="Exit", underline=1, command=self._quit)
        menubar.add_cascade(label="File", menu=fileMenu)

        # The second panel holds controls
        self.player = None
        self.videopanel = ttk.Frame(self.parent)
        self.canvas = Tk.Canvas(self.videopanel).pack(fill=Tk.BOTH, expand=1)
        self.videopanel.pack(fill=Tk.BOTH, expand=1)

        ctrlpanel = ttk.Frame(self.parent)
        pause = ttk.Button(ctrlpanel, text="Pause", command=self.OnPause)
        play = ttk.Button(ctrlpanel, text="Play", command=self.OnPlay)
        stop = ttk.Button(ctrlpanel, text="Stop", command=self.OnStop)
        next = ttk.Button(ctrlpanel, text="Next", command=self.OnNext)
        previous = ttk.Button(ctrlpanel,
                              text="Previous",
                              command=self.OnPrevious)
        volume = ttk.Button(ctrlpanel, text="Volume", command=self.OnSetVolume)
        pause.pack(side=Tk.LEFT)
        play.pack(side=Tk.LEFT)
        stop.pack(side=Tk.LEFT)
        next.pack(side=Tk.LEFT)
        previous.pack(side=Tk.LEFT)
        volume.pack(side=Tk.LEFT)
        self.volume_var = Tk.IntVar()
        self.volslider = Tk.Scale(ctrlpanel,
                                  variable=self.volume_var,
                                  command=self.volume_sel,
                                  from_=0,
                                  to=100,
                                  orient=Tk.HORIZONTAL,
                                  length=100)
        self.volslider.pack(side=Tk.LEFT)
        ctrlpanel.pack(side=Tk.BOTTOM)

        ctrlpanel2 = ttk.Frame(self.parent)
        self.scale_var = Tk.DoubleVar()
        self.timeslider_last_val = ""
        self.timeslider = Tk.Scale(ctrlpanel2,
                                   variable=self.scale_var,
                                   command=self.scale_sel,
                                   from_=0,
                                   to=1000,
                                   orient=Tk.HORIZONTAL,
                                   length=500)
        self.timeslider.pack(side=Tk.BOTTOM, fill=Tk.X, expand=1)
        self.timeslider_last_update = time.time()
        ctrlpanel2.pack(side=Tk.BOTTOM, fill=Tk.X)

        # VLC player controls
        self.Instance = vlc.Instance()
        self.player = self.Instance.media_player_new()

        self.timer = ttkTimer(self.OnTimer, 1.0)
        self.timer.start()

        self.parent.update()

    def printSomething(self, txt):
        # if you want the button to disappear:
        # button.destroy() or button.pack_forget()
        # 0 is unnecessary

        if len(self.label_arr) > 0:
            self.label_arr[-1].destroy()
        label = Tk.Label(root, text=txt)
        # this creates x as a new label to the GUI
        label.pack()
        self.label_arr.append(label)

    def OnNext(self):

        if self.episode_num < len(self.videos) - 1:  ##in season
            self.episode_num += 1
            #    q1="""TRUNCATE `personal_use`.`episode_table`;"""
            #    execute_query(connection, q1)
            #    q1="""INSERT INTO `personal_use`.`episode_table`
            #            (`episode_num`,
            #            `episode_time`,
            #            `episode_season`)
            #                VALUES
            #                ("""+str(self.episode_num+1)+""","""+str(self.episode_time)+""","""+str(self.episode_season)+""");"""
            #    execute_query(connection,q1)
            q1 = """UPDATE `personal_use`.`episode_table`
                SET
                `episode_num`= """ + str(self.episode_num + 1) + """,
                `episode_time` = """ + str(self.episode_time) + """,
                `episode_season`=""" + str(self.episode_season) + """
                WHERE  `show_name`='""" + str(self.show_name) + """';
                """
            execute_query(connection, q1)

            self.Create(self.dirname, self.videos[self.episode_num])
            self.OnPlay()
        else:  ##start new season
            self.episode_season += 1
            self.episode_num = 1
            #q1 = """TRUNCATE `personal_use`.`episode_table`;"""
            #execute_query(connection, q1)
            #q1 = """INSERT INTO `personal_use`.`episode_table`
            #                    (`episode_num`,
            #                    `episode_time`,
            #                    `episode_season`)
            #                        VALUES
            #                        (""" + str(self.episode_num) + """,""" + str(self.episode_time) + """,""" + str(
            #    self.episode_season) + """);"""
            #execute_query(connection, q1)

            q1 = """UPDATE `personal_use`.`episode_table`
                           SET
                           `episode_num`= """ + str(self.episode_num) + """,
                           `episode_time` = """ + str(self.episode_time) + """,
                           `episode_season`=""" + str(
                self.episode_season) + """
                           WHERE  `show_name`='""" + str(
                    self.show_name) + """';
                           """
            execute_query(connection, q1)

            self.episode_num -= 1  ##so it will match the array
            self.OnOpen()

    def OnPrevious(self):

        if self.episode_num > 0:  ##in season
            self.episode_num -= 1
            #q1 = """TRUNCATE `personal_use`.`episode_table`;"""
            #execute_query(connection, q1)
            #q1 = """INSERT INTO `personal_use`.`episode_table`
            #                    (`episode_num`,
            #                    `episode_time`,
            #                    `episode_season`)
            #                        VALUES
            #                        (""" + str(self.episode_num+1) + """,""" + str(self.episode_time) + """,""" + str(
            #    self.episode_season) + """);"""
            #execute_query(connection, q1)

            q1 = """UPDATE `personal_use`.`episode_table`
                                       SET
                                       `episode_num`= """ + str(
                self.episode_num + 1) + """,
                                       `episode_time` = """ + str(
                    self.episode_time) + """,
                                       `episode_season`=""" + str(
                        self.episode_season) + """
                                       WHERE  `show_name`='""" + str(
                            self.show_name) + """';
                                       """
            execute_query(connection, q1)

            self.Create(self.dirname, self.videos[self.episode_num])
            self.OnPlay()
        else:  ##back to previous season
            self.episode_season -= 1

            #self.dirname = r"C:\Users\tonyh\OneDrive\Desktop\shows and movies\shows\that 70s show\season"
            #self.dirname += str(self.episode_season)

            self.dirname = r"C:\Users\tonyh\OneDrive\Desktop\shows and movies\shows"
            self.dirname += "\\"
            self.dirname += self.show_name
            self.dirname += "\\"
            self.dirname += "season"
            self.dirname += str(self.episode_season)

            self.mediaList = self.Player.media_list_new()
            self.videos = os.listdir(self.dirname)

            self.episode_num = len(self.videos)

            #q1 = """TRUNCATE `personal_use`.`episode_table`;"""
            #execute_query(connection, q1)
            #q1 = """INSERT INTO `personal_use`.`episode_table`
            #                                (`episode_num`,
            #                                `episode_time`,
            #                                `episode_season`)
            #                                    VALUES
            #                                    (""" + str(self.episode_num) + """,""" + str(
            #    self.episode_time) + """,""" + str(
            #    self.episode_season) + """);"""
            #execute_query(connection, q1)

            q1 = """UPDATE `personal_use`.`episode_table`
                                                   SET
                                                   `episode_num`= """ + str(
                self.episode_num) + """,
                                                   `episode_time` = """ + str(
                    self.episode_time) + """,
                                                   `episode_season`=""" + str(
                        self.episode_season) + """
                                                   WHERE  `show_name`='""" + str(
                            self.show_name) + """';
                                                   """
            execute_query(connection, q1)

            self.episode_num -= 1  ##so it will match the array
            self.OnOpen()

    def OnExit(self, evt):
        """Closes the window.
        """
        self.Close()

    def OnOpen(self):
        """Pop up a new dialow window to choose a file, then play the selected file.
        """
        # if a file is already running, then stop it.
        self.OnStop()

        # Create a file dialog opened in the current home directory, where
        # you can display all kind of files, having as title "Choose a file".
        #p = pathlib.Path(os.path.expanduser("~"))
        p = pathlib.Path(
            os.path.expanduser(
                r"C:\Users\tonyh\OneDrive\Desktop\shows and movies\shows\show names"
            ))
        fullname = askopenfilename(initialdir=p,
                                   title="choose your file",
                                   filetypes=(("all files", "*.*"),
                                              ("mp4 files", "*.mp4")))
        #if os.path.isfile(fullname):
        #    print(fullname)
        #    splt = os.path.split(fullname)

        #dirname = os.path.dirname(fullname)

        #new addition
        filename = os.path.basename(fullname)
        filename = filename[:-4]  ##deletes the .txt from the name

        print(filename)
        #self.dirname=r"C:\Users\tonyh\OneDrive\Desktop\shows and movies\shows\that 70s show\season1"

        ##defining the properties of the show:

        q1 = """SELECT `episode_table`.`episode_num`,
            `episode_table`.`episode_time`,
            `episode_table`.`episode_season`
    
            FROM `personal_use`.`episode_table`

            WHERE `episode_table`.`show_name`='""" + filename + """'"""
        results = read_query(connection, q1)
        self.episode_num = results[0][
            0] - 1  ##subracting 1 to match array position of real episode
        self.episode_season = results[0][2]
        self.episode_time = results[0][1]
        self.show_name = filename

        ##new addition
        self.dirname = r"C:\Users\tonyh\OneDrive\Desktop\shows and movies\shows"
        self.dirname += "\\"
        self.dirname += filename
        self.dirname += "\\"
        self.dirname += "season"
        self.dirname += str(self.episode_season)

        ##before updating

        #self.dirname=r"C:\Users\tonyh\OneDrive\Desktop\shows and movies\shows\that 70s show\season"
        #self.dirname+=str(self.episode_season)

        ##tony
        ##creating the array of episodes
        self.mediaList = self.Player.media_list_new()
        self.videos = os.listdir(self.dirname)

        for v in self.videos:
            self.mediaList.add_media(
                self.Player.media_new(os.path.join(self.dirname, v)))
            self.listPlayer = self.Player.media_list_player_new()
            self.listPlayer.set_media_list(self.mediaList)

        self.Create(self.dirname, self.videos[self.episode_num])
        # Creation
        #self.Media = self.Instance.media_new(str(os.path.join(dirname, filename)))
        #self.player.set_media(self.Media)
        # Report the title of the file chosen
        # title = self.player.get_title()
        #  if an error was encountred while retriving the title, then use
        #  filename
        # if title == -1:
        #    title = filename
        # self.SetTitle("%s - tkVLCplayer" % title)

        # set the window id where to render VLC's video output

        ##tony: you turned of this so it opens a seperate window

        #if platform.system() == 'Windows':
        #    self.player.set_hwnd(self.GetHandle())
        #else:
        #    self.player.set_xwindow(self.GetHandle())  # this line messes up windows
        # FIXME: this should be made cross-platform

        self.OnPlay()

        # set the volume slider to the current volume
        # self.volslider.SetValue(self.player.audio_get_volume() / 2)
        self.volslider.set(self.player.audio_get_volume())

    def Create(self, dirname, filename):

        if self.first_entrence == 0:  ##if first time then start from the time you stopped
            self.Media = self.Instance.media_new(
                str(os.path.join(dirname, filename)))

            self.Media.add_option('start-time=' + str(self.episode_time) + '')
            self.player.set_media(self.Media)
            self.first_entrence += 1

        else:
            self.Media = self.Instance.media_new(
                str(os.path.join(dirname, filename)))
            self.player.set_media(self.Media)

        self.video_len = VideoFileClip(str(os.path.join(dirname, filename)))
        self.video_len = self.video_len.duration
        self.running = 1
        self.printSomething(filename)

    def OnPlay(self):
        """Toggle the status to Play/Pause.
        If no file is loaded, open the dialog window.
        """
        # check if there is a file to play, otherwise open a
        # Tk.FileDialog to select a file
        if not self.player.get_media():
            self.OnOpen()

        else:
            # Try to launch the media, if this fails display an error message
            if self.player.play() == -1:
                self.errorDialog("Unable to play.")

    def GetHandle(self):
        return self.videopanel.winfo_id()

    # def OnPause(self, evt):
    def OnPause(self):
        """Pause the player.
        """
        self.player.pause()

    def OnStop(self):
        """Stop the player.
        """
        self.player.stop()
        # reset the time slider
        if self.first_entrence != 0:
            self.timeslider.set(0)

    def OnTimer(self):
        """Update the time slider according to the current movie time.
        """

        if self.player == None:
            return
        # since the self.player.get_length can change while playing,
        # re-set the timeslider to the correct range.
        length = self.player.get_length()
        dbl = length * 0.001
        self.timeslider.config(to=dbl)

        # update the time on the slider
        tyme = self.player.get_time()
        if tyme == -1:
            tyme = 0
        dbl = tyme * 0.001

        if self.first_entrence != 0:  ##important for starting from saved time
            self.episode_time = dbl
        self.timeslider_last_val = ("%.0f" % dbl) + ".0"

        # don't want to programatically change slider while user is messing with it.
        # wait 2 seconds after user lets go of slider
        if time.time() > (self.timeslider_last_update + 2.0):
            self.timeslider.set(dbl)

        if self.running == 1:
            if dbl > self.video_len - 1:
                time.sleep(5)
                if dbl > self.video_len - 1:
                    self.running = 0
                    self.player.set_time(0)
                    self.OnNext()

    def scale_sel(self, evt):
        if self.player == None:
            return
        nval = self.scale_var.get()
        sval = str(nval)
        if self.timeslider_last_val != sval:
            # this is a hack. The timer updates the time slider.
            # This change causes this rtn (the 'slider has changed' rtn) to be invoked.
            # I can't tell the difference between when the user has manually moved the slider and when
            # the timer changed the slider. But when the user moves the slider tkinter only notifies
            # this rtn about once per second and when the slider has quit moving.
            # Also, the tkinter notification value has no fractional seconds.
            # The timer update rtn saves off the last update value (rounded to integer seconds) in timeslider_last_val
            # if the notification time (sval) is the same as the last saved time timeslider_last_val then
            # we know that this notification is due to the timer changing the slider.
            # otherwise the notification is due to the user changing the slider.
            # if the user is changing the slider then I have the timer routine wait for at least
            # 2 seconds before it starts updating the slider again (so the timer doesn't start fighting with the
            # user)
            # selection = "Value, last = " + sval + " " + str(self.timeslider_last_val)
            # print("selection= ", selection)
            self.timeslider_last_update = time.time()
            mval = "%.0f" % (nval * 1000)
            self.player.set_time(int(mval))  # expects milliseconds

    def volume_sel(self, evt):
        if self.player == None:
            return
        volume = self.volume_var.get()
        if volume > 100:
            volume = 100
        if self.player.audio_set_volume(volume) == -1:
            self.errorDialog("Failed to set volume")

    def OnToggleVolume(self, evt):
        """Mute/Unmute according to the audio button.
        """
        is_mute = self.player.audio_get_mute()

        self.player.audio_set_mute(not is_mute)
        # update the volume slider;
        # since vlc volume range is in [0, 200],
        # and our volume slider has range [0, 100], just divide by 2.
        self.volume_var.set(self.player.audio_get_volume())

    def OnSetVolume(self):
        """Set the volume according to the volume sider.
        """
        volume = self.volume_var.get()
        print("volume= ", volume)
        # volume = self.volslider.get() * 2
        # vlc.MediaPlayer.audio_set_volume returns 0 if success, -1 otherwise
        if volume > 100:
            volume = 100
        if self.player.audio_set_volume(volume) == -1:
            self.errorDialog("Failed to set volume")

    def errorDialog(self, errormessage):
        """Display a simple error dialog.
        """
        edialog = Tk.tkMessageBox.showerror(self, 'Error', errormessage)

    def _quit(self):
        q1 = """UPDATE `personal_use`.`episode_table` SET `episode_num` = """ + str(
            self.episode_num + 1) + """,`episode_time` = '""" + str(
                self.episode_time) + """',`episode_season` ='""" + str(
                    self.episode_season) + """'   WHERE
        `show_name` = '""" + str(self.show_name) + """';"""

        execute_query(connection, q1)
        print("_quit: bye")
        root = Tk_get_root()
        root.quit()  # stops mainloop
        root.destroy()  # this is necessary on Windows to prevent
        # Fatal Python Error: PyEval_RestoreThread: NULL tstate
        os._exit(1)