titellänge

09/06/2012 17:57 H@CT0R#1
spiele über soundplay verschiedene .mp3s ab, damit der script sich nicht vor beendigung des abspielens beendet oder den nächsten titel startet, verwende ich ein sleep, da ich allerdings nicht für jeden titel ein spezielles sleep mit der spiellänge des titels machen möchte (zu aufwändig) suche ich eine möglichkeit die spiellänge einer .mp3 auszulesen...google hat noch nicht wirklich geholfen...

jemand hier eine idee?
09/06/2012 18:01 Ludder231#2
Guck dir mal
PHP Code:
_soundlength 
an. Außerdem kansnt du ja bei _soundplay/soundplay das Parameter setzen
PHP Code:
SoundPlay "filename" [, wait] )

wait [optionalThis flag determines if the script should wait for the sound to finish before continuing:
wait until sound has finished
= continue script while sound is playing (default) 
MfG Ludder231
09/06/2012 18:04 H@CT0R#3
Quote:
Originally Posted by Ludder231 View Post
Guck dir mal
PHP Code:
_soundlength 
an. Außerdem kansnt du ja bei _soundplay/soundplay das Parameter setzen
PHP Code:
SoundPlay "filename" [, wait] )

wait [optionalThis flag determines if the script should wait for the sound to finish before continuing:
wait until sound has finished
= continue script while sound is playing (default) 
MfG Ludder231
okay, danke, werd ich mir anschauen ;)
09/06/2012 18:13 Logtetsch#4
Relativ einfach, wenn man weiß, wie man mit der AutoIT Hilfe umzugehen hat ;)

Code:
#RequireAdmin
#include <Sound.au3>

Local $hFile = "Song.mp3"
_SoundOpen ($hFile)
if not @error Then
	Local $hFileLenght = _SoundLength($hFile,1)
	if not @error Then
		_SoundPlay ($hFile, 1)
	EndIf
EndIf
09/06/2012 18:16 Ludder231#5
Quote:
Originally Posted by Logtetsch View Post
Relativ einfach, wenn man weiß, wie man mit der AutoIT Hilfe umzugehen hat ;)

Code:
#RequireAdmin
#include <Sound.au3>

Local $hFile = "Song.mp3"
_SoundOpen ($hFile)
if not @error Then
	Local $hFileLenght = _SoundLength($hFile,1)
	if not @error Then
		_SoundPlay ($hFile, 1)
	EndIf
EndIf
Ja, so hast du ihm aber alles vorgesagt. Ich hab ihm nur gesagt welchen Befehl man benutzt. Da ist doch der Lerneffekt viel höher. :)
09/06/2012 18:30 Logtetsch#6
Mir ist gerade langweilig, deshalb habe ich sogar einen kleinen Audioplayer gescriptet.

Code:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <Sound.au3>

Global $txt_NoTitel = "???"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Audioplayer", 163, 78, 192, 114)
$Progress1 = GUICtrlCreateProgress(5, 5, 150, 16)
$btn_OpenFile = GUICtrlCreateButton("open", 5, 25, 60, 25)
$btn_HandleFile = GUICtrlCreateButton("play/ break", 95, 25, 60, 25)
$lbl_Title = GUICtrlCreateLabel ($txt_NoTitel, 5, 58, 50, 17)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $hFile, $length, $FileName, $io = 0

While Sleep (10)
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case -3
			Exit


		Case $btn_OpenFile
			Local $path = FileOpenDialog ("Select mp3", @ScriptDir, "Audio (*.mp3; *.wav;)", 1+4)
			if @error Then
				GUICtrlSetData ($lbl_Title, $txt_NoTitel)
			Else
				$hFile = _SoundOpen ($path)
				if not @error Then
					Local $sSplit = StringSplit ($path, "\")
					if IsArray ($sSplit) Then
						Local $sSize = UBound ($sSplit) -1
						if $sSize > 0 Then
							GUICtrlSetData ($lbl_Title, $sSplit[$sSize])
						EndIf
					EndIf
				Else
					$hFile = 0
					MsgBox (46,"Error","Cannot open file!")
					GUICtrlSetData ($lbl_Title, $txt_NoTitel)
				EndIf
			EndIf



		Case $btn_HandleFile
			if $hFile <> "" Then
				if $io = 0 Then
					_LPlaySound($hFile)
					$io = 1
				Else
					_LPauseSound()
					$io = 0
				EndIf
			Else
				MsgBox (64,"Info","You have to select a file!")
			EndIf

	EndSwitch

	if $hFile <> 0 or $hFile <> "" Then
		Local $hLenght = _SoundLength ($hFile, 2)
		Local $hPosition = _SoundPos ($hFile, 2)
		if not @error Then
			Local $SoundLenght = $hLenght / 1000
			Local $SoundPosition = $hPosition / 1000

			Local $secDiff = $SoundLenght / $SoundPosition
			Local $procDiff = 100 / $secDiff

			GUICtrlSetData ($Progress1, $procDiff)
		EndIf
	EndIf

WEnd

Func _LPlaySound($file)
	_SoundPlay ($file, 0)
EndFunc

Func _LPauseSound()
	_SoundPause($hFile)
EndFunc
Wollte eigentlich die Progressbar zu Ende scripten, aber leider muss ich meine Termine einhalten. Werde es später editieren ;)

€: Paar kleine Textänderungen. Zudem funktioniert nun die Progressbar und habe einen Label hinzugefügt, der den Soundtitel anzeigt!