Data-to-Dataの比較検査プログラム(Windows版)は、試用結果待ち。
Data-to-Photoの比較検査プログラム(Mac版)は、忙しさの明け待ち。
Data-to-Photoの比較検査プログラムは、カメラ固定方法の物色。
ということでプログラミングの空きが発生したので、ChatGPTで簡易Playerソフトの開発をしてみた。
まずは練習で、MP3 Player。
1発でただ単に再生ができるコードを提示してくれた。
それを改善しようとして、ドツボに入ってく・・・
まず、コードをコピーしても余計な文字が入り、そのままでは動作しない。
指摘すると、改善したというが、ほとんど改善されていない。
最初のコードでいいや、としたんだが、今度は内臓SSDやHDDの中にMP3ファイルが無い。
愕然としてしまったが、よく考えれば、車載用のCDを作成していたころの13年以上前から後はMP3ファイルを扱った記憶が無い。
カーナビでDVD再生をしだしてから、DVDしか車載してなかったよ。
WebからMP3ファイルをダウンロードしたら、再生できた。
まあ、使わないんだけどね。
興味がある方は、
Pythonをダウンロードしてインストール
VS Codeをダウンロードしてインストール
メモ帳で、
install pygame.bat
などのファイル名で、
pip install pygame
pause
の内容のバッチファイルを作成して、実行
VS Codeで
MP3Player001.py
などのファイル名で、次のコードのプログラムを作成して、動作させてみてください。
import tkinter as tk
from tkinter import filedialog
import pygame, os
pygame.mixer.init()
root = tk.Tk()
root.title("MP3 Player")
root.geometry("500x300")
files = []
index = 0
playing = False
def add_files():
global files
f = filedialog.askopenfilenames(filetypes=[("MP3", "*.mp3")])
files += list(f)
listbox.delete(0, tk.END)
for x in files: listbox.insert(tk.END, os.path.basename(x))
def play():
global index, playing
if files:
pygame.mixer.music.load(files[index])
pygame.mixer.music.play()
playing = True
title.config(text=os.path.basename(files[index]))
def pause():
pygame.mixer.music.pause()
def resume():
pygame.mixer.music.unpause()
def stop():
global playing
pygame.mixer.music.stop()
playing = False
def prev():
global index
if files:
index = (index - 1) % len(files)
play()
def next_song():
global index
if files:
index = (index + 1) % len(files)
play()
def select(event):
global index
if listbox.curselection():
index = listbox.curselection()[0]
play()
def volume(v):
pygame.mixer.music.set_volume(float(v))
title = tk.Label(root, text="MP3 Player", font=("Arial", 14))
title.pack(pady=10)
listbox = tk.Listbox(root, height=8, width=55)
listbox.pack()
listbox.bind("<Double-Button-1>", select)
tk.Button(root, text="MP3を追加", command=add_files).pack(pady=8)
frame = tk.Frame(root)
frame.pack()
tk.Button(frame, text="|◀", width=6, command=prev).pack(side=tk.LEFT, padx=3)
tk.Button(frame, text="▶", width=6, command=play).pack(side=tk.LEFT, padx=3)
tk.Button(frame, text="||", width=6, command=pause).pack(side=tk.LEFT, padx=3)
tk.Button(frame, text="▶", width=6, command=resume).pack(side=tk.LEFT, padx=3)
tk.Button(frame, text="■", width=6, command=stop).pack(side=tk.LEFT, padx=3)
tk.Button(frame, text="▶|", width=6, command=next_song).pack(side=tk.LEFT, padx=3)
tk.Label(root, text="音量").pack(pady=(15, 0))
tk.Scale(root, from_=0, to=1, resolution=0.01, orient=tk.HORIZONTAL,
length=300, command=volume).set(0.8)
tk.Scale(root, from_=0, to=1, resolution=0.01, orient=tk.HORIZONTAL,
length=300, command=volume).pack()
root.mainloop()
このプログラムはAI(ChatGPT)を利用して作成したものです。
自由にコピー・改変等できるようです。
プログラムの利用によって生じた、いかなる損害やトラブルについて、一切の責任を負いません。
コメント
コメントを投稿