-2

I'm new to programming. I'm trying to create a video player GUI using tkinter in python and TkVideoplayer to play my video files.

I can only find working volume control function for audio files using pygame, but i can't find any for video files' audio. My question is : "Can I control the volume of my video files' audio in python?" If yes, : "How can I increase or decrease my video files audio in python? "

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 1
    Too generic question. Learn to break down the whole project into parts. Figure out how you'll achieve each and ask question pertaining to a module if you still cant find solution – Shreyesh Desai Sep 01 '23 at 08:37
  • Depends on the playing backend you use - the VLC library for example of course has a volume control. – TheEagle Sep 01 '23 at 08:44
  • @ShreyeshDesai I apologize, I'm still new to this and I can't even explain correctly... but thank you for answering my question. – user22482238 Sep 01 '23 at 09:06

1 Answers1

0

You can try for increase and decrease files using moviepy

from tkinter import filedialog
from moviepy.editor import VideoFileClip

class VideoPlayer:
    def __init__(self, root):
        self.root = root
        self.root.title("Video Player")
        self.frame = tk.Frame(self.root)
        self.frame.pack()
        self.video_path = None
        self.volume = 1.0
        self.create_widgets()

    def create_widgets(self):
        # Open File button
        self.open_button = tk.Button(self.frame, text="Open Video", command=self.open_video)
        self.open_button.pack()

        # Volume control
        self.volume_label = tk.Label(self.frame, text="Volume")
        self.volume_label.pack()

        self.volume_slider = tk.Scale(self.frame, from_=0, to=1, resolution=0.01, orient=tk.HORIZONTAL,
                                      command=self.set_volume)
        self.volume_slider.set(self.volume)
        self.volume_slider.pack()

        # Play button
        self.play_button = tk.Button(self.frame, text="Play", command=self.play_video)
        self.play_button.pack()

    def open_video(self):
        file_path = filedialog.askopenfilename(filetypes=[("Video Files", "*.mp4 *.avi *.mkv")])
        if file_path:
            self.video_path = file_path

    def set_volume(self, volume):
        self.volume = float(volume)

    def play_video(self):
        if self.video_path:
            clip = VideoFileClip(self.video_path)
            clip = clip.volumex(self.volume)
            clip.preview()

if __name__ == "__main__":
    root = tk.Tk()
    app = VideoPlayer(root)
    root.mainloop()
tpd
  • 11
  • 4