Hey Leute, ich habe folgendes Problem... ich habe mir eine Homeautomatisierung selber gebaut... jetzt geht es noch um bugfixes ... ich habe mir ein Programm geschrieben (vielleicht nicht ganz so sauber weil ich am rumtesten bin)
Es geht inzwischen um ein paar einstellungen, folgendes ich habe mir ein Wetter system gebaut und möchte jetzt auf einem Bildschirm ein bestimmtes Video sehen wenn es Regnet und wenn die Sonne scheint ein anderes.
Dieses System habe ich aber auch mit meiner Klingel und anderen eigentschaften ausgerüstet.
Am Pi selber ist ein Hifi Amp2 ... Audio macht auch keine Faxen, nur video ...
Problemstellung:
Sobald ich ein Audio file abgespielt habt bleibt der Monitor schwarz wenn ich ein Video danach abspielen möchte.
Wenn ich das Script neustarte kann ich ein Video abspielen und danach auch soviele sounds wie ich möchte, aber wenn ich danach wieder ein Video abspielen will bleibt der Monitor schwarz.
import RPi.GPIO as GPIO
import os
import sys
import paho.mqtt.client as mqtt
from PIL import Image
from subprocess import Popen
import subprocess
import pygame
pfadfile = ("/home/pi/file/")
playmode = "0"
player ="0"
file = "0"
chan1 = 0
trenn=":"
voll= 0.1
volr= 0.1
ent="0"
modus = "0"
os.system('export DISPLAY=:0')
if sys.argv[2] == "0":
topic ="/0000/ent"
elif sys.argv[2] == "1":
topic ="/0001/ent"
elif sys.argv[2] == "2":
topic ="/0002/ent"
elif sys.argv[2] == "3":
topic ="/0003/ent"
elif sys.argv[2] == "4":
topic ="/0004/ent"
elif sys.argv[2] == "5":
topic ="/0005/ent"
elif sys.argv[2] == "6":
topic ="/0006/ent"
elif sys.argv[2] == "7":
topic ="/0007/ent"
topic = sys.argv[1] + topic
print(topic)
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client.subscribe(topic)
def on_message(client, userdata, msg):
global playmode
global player
global trenn
global ent
global subprocess
global file
global audio1
global chan1
global voll
global volr
global modus
message = msg.payload
print(message)
if trenn in message:
a,file,ent,voll,volr= message.split(":")
file = (pfadfile + file)
voll=float(voll)
volr=float(volr)
if a=='play':
playmode = "1"
elif a=="playl":
playmode ="2"
if ent=='audio':
modus="1"
elif ent=='video':
modus="2"
print('Play/Lopp')
print(playmode)
print('Audio/Video')
print(modus)
if(player=="2" and modus=="1"):
player="0"
if(player=="2" and modus=="2"):
player="0"
if(player=="2" and modus=="2"):
pygame.mixer.stop()
os.system('killall pygame.bin')
if(player=="1" and modus=="1"):
os.system('killall omxplayer.bin')
player="0"
if(player =="1" and modus=="2"):
os.system('killall omxplayer.bin')
player = "0"
if (player=="0" and playmode =="1" and modus=="1"):
pygame.mixer.init(frequency=22050,size=-16,channels=4)
audio1 = pygame.mixer.Sound(file) #audio 1 mixer zu ordnen
chan1 = pygame.mixer.find_channel() # freien channel definieren
chan1.set_volume(voll,volr) #lautstrke dem channel zuweisen
print(chan1.set_volume(voll,volr))
chan1.play (audio1)
player="2"
if (player=="0" and playmode =="2" and modus=="1"):
pygame.mixer.init(frequency=22050,size=-16,channels=4)
audio1 = pygame.mixer.Sound(file)
chan1 = pygame.mixer.find_channel()
chan1.set_volume(voll,volr)
chan1.play (audio1,loops = -1)
if (player=="0" and playmode =="1" and modus=="2"):
omxc = Popen(['omxplayer','-b','--no-osd','-o','alsa', file])
player = "1"
elif (player=="0" and playmode =="2" and modus=="2"):
omxc = Popen(['omxplayer','-b', '--loop','--no-osd','-o','local', file])
player = "1"
if (message=="stop" and player=="0" and modus=="1"):
pygame.mixer.stop()
os.system('killall pygame.bin')
if (message=="stop" and player=="1" and modus=="2"):
os.system('killall omxplayer.bin')
if (message=="tvoff"):
os.system('killall omxplayer.bin')
os.system('tvservice -o')
if (message=="tvon"):
os.system('tvservice -p')
##MQTT Variablen und Settings
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("192.168.178.35", 1883, 60)
client.loop_forever()
Display More
Die Consolen ausgabe wenn er ein Video abspielt sieht so aus :
Video codec omx-h264 width 1280 height 720 profile 100 fps 29.970030
Audio codec aac channels 2 samplerate 44100 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
V:PortSettingsChanged: 1280x720@29.97 interlace:0 deinterlace:0 anaglyph:0 par:1.00 display:0 layer:0 alpha:255 aspectMode:0
Die Consolen ausgabe wenn er ein Video abspielen soll aber Schwarz bleibt
Video codec omx-h264 width 1280 height 720 profile 100 fps 29.970030
Audio codec aac channels 2 samplerate 44100 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
V:PortSettingsChanged: 1280x720@29.97 interlace:0 deinterlace:0 anaglyph:0 par:1.00 display:0 layer:0 alpha:255 aspectMode:0
---------------------------------------------------------------
Leider kann ich den OMXplayer nicht sagen das die Lautstärke links und rechts unterschiedlich sein soll , deswegen muss ich mit beiden Systemen arbeiten.
Vermutung lag das der pygame mixer sich nicht richtig beendet.. aber denke mit einem Stop und kill sollte es gewesen sein oder ?
Vielleicht hat von euch noch wer eine Idee!