QuickTime 7 : extract from position an audio preview

Hi All (Again :slight_smile: ),

Thank you very much for this forum and all the posts on. It is really hellpfull to start to better understand how what with actionscript.

Before the arrival of QT7 I was using this script to create some preview of audio files. Basically, I can set a begin point, the duration and automatically extract this portion to a new file as .wav.

QT7 add new great features to quicktime, but also break this script. I cannot handle at this time what exactly is going wrong. I see something like a wrong type on “time scale” but not sure at all…

If someone have an idea on it, that could be fun. Maybe an english lesson too :wink: sorry for my frenglish.

tell application "QuickTime Player"
	activate
	
	try
		if not (exists movie 1) then error "No movies are open."
		
		stop every movie
		
		-- CHECK FOR QUICKTIME PRO
		if QuickTime Pro installed is false then
			set the target_URL to "http://www.apple.com/quicktime/download/"
			display dialog "This script requires QuickTime Pro." & return & return & ¬
				"If this computer is currently connected to the Internet, " & ¬
				"click the "Upgrade" button to visit the QuickTime Website at:" & ¬
				return & return & target_URL buttons {"Upgrade", "Cancel"} default button 2
			ignoring application responses
				tell application "Finder"
					open location target_URL
				end tell
			end ignoring
			error number -128
		end if
		
		-- set the position for starting the preview
		if not (exists movie 1) then return
		stop every movie
		set this_movie to the name of movie 1
		set the time_scale to the time scale of movie 1
		set the play_point to the current time of movie 1
		set the high_number to the duration of movie 1
		set the low_number to 0
		repeat
			display dialog "Start position of  "" & this_movie & ""." & ¬
				return & return & "Enter a number between " & the low_number & " and " & the (round high_number / time scale) & ":" default answer play_point
			try
				if the text returned of the result is not "" then ¬
					set the this_time to the text returned of the result as number
				if the this_time is greater than or equal to the low_number and ¬
					the this_time is less than or equal to the high_number and ¬
					the this_time mod 1 is equal to 0 then
					exit repeat
				end if
			end try
		end repeat
		set the current time of movie 1 to this_time * time scale
		
		-- set the duration of the preview
		set the low_number to 5
		set the high_number to 290
		repeat
			display dialog "Enter a duration between " & the low_number & " and " & the high_number & ":" default answer ""
			try
				if the text returned of the result is not "" then ¬
					set the requested_number to the text returned of the result as number
				if the requested_number is greater than or equal to the low_number and ¬
					the requested_number is less than or equal to the high_number then exit repeat
			end try
		end repeat
		
		-- get the name of the movie
		set the movie_name to the name of movie 1 & ".preview.wav"
		
		-- check the start and end position for the selection
		set the current_time to the current time
		select movie 1 at current_time to (current_time + (requested_number * (time scale)))
		
		-- create a new movie and copy the selection inside
		copy movie 1
		make new movie
		paste movie 1
		rewind movie 1
		select none of movie 1
		
		-- check to see if the opened movie can be exported
		if (can export movie 1 as wave) is true then
			-- prompt the user for a name and location
			set the new_file to ¬
				choose file name with prompt "Enter a name and choose a location for the new file:" default name movie_name
			-- export the movie as Wave file
			export movie 1 to new_file as wave using default settings
			-- close the movie
			close movie 1 saving no
			close movie 1 saving no
		else
			error "This movie cannot be exported as a Wave Audio Preview."
		end if
	on error error_message number error_number
		if the error_number is not -128 then
			beep
			display dialog error_message buttons {"Cancel"} default button 1
		end if
	end try
end tell

Model: PowerBook
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)

I always have the same concern, I do not find a solution on it…

display dialog "Can't make «class tmsc» of application \"QuickTime Player\" into type number." buttons {"Cancel"} default button 1
		"QuickTime Player got an error: User canceled."

Thank you Jacques.
This is a double post, my old one was reactivated, it’s a long story :P.
Maybe admins can delete this one.