Hi,
like my previous message, this have been tested running Mac OS X.
REALbasic 5.5.4 for Mac OS X
Mac OS X 10.3.7
The Sound Class entry in the Language Reference already gives a clue to do that,
but since the clue is ... not followed by an example.
HTH,
Emile
Here is a simple step by step.
Of course, you need to have a bunch of StaticTexts (STRunning to display the
ellapsed time, STFull to display the total time), two sliders (not mandatory,
but usefull: sVolume and sPan [set LiveUpdate to True]), etc.
Of course, .LongTime returns here (for me and because my Hour settings are by
default to 24 hours) the time as [h]h:mm:ss and not [h]h:mm:ss AM|PM.
Here I go:
a. Add a new Class to the project,
b. Give it:
Name: SoundThread
Super: Thread
c. Open the target window (the window where the Sound Playing code is),
d. Drag the SoundThread Class to that window:
a. you get a nice icon (invisible at running time),
Change its name from 'SoundThread1' to 'mySoundThread'
b. you get a new entry under the Controls disclosure triangle:
'mySoundThread';
e. Click in the Controls disclosure triangle to open it,
Place the following code in the Run entry (of the 'mySoundThread'):
//
// mySoundThread.Run
//
// wMain’s Window property:
// aSoundFileFI As FolderItem
// aSound As Sound
//
Dim sTicks As Integer
Dim sRunTime As New Date
Dim sTotalTime As New Date
Dim sEM As EditableMovie
// Opens the file as an EditableMovie
sEM = aSoundFileFI.OpenEditableMovie
// Get the file length
sTotalTime.TotalSeconds = sEM.Duration
// Close the EditableMovie
sEM = Nil // Release the memory allocated to sEM
// Get the sound
aSound = aSoundFileFI.OpenAsSound
// Display the total time
STFull.Caption = sTotalTime.LongTime
// Play the sound
aSound.Play
// Set the sound start
sTicks = Ticks
Do
// Set the running time
sRunTime.TotalSeconds = (Ticks - sTicks) / 60
// Display the ellapsed time
STRunning.Caption = sRunTime.LongTime
// Allows the user to stop playing the sound
If UserCancelled Then
// Stop
aSound.Stop
// Quit the loop
Exit
End If
// Set the volume
aSound.Volume = sVolume.Value
// Set the Pan
aSound.Pan = sPan.Value
Loop Until Not aSound.IsPlaying
In the Play button Action’s event, place:
Sub Action()
// Execute the Thread
mySoundThread.Run
End Sub
Now, you can hear music and do something else (the interface is not frozen
during the playback).
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|