[futurebasic] Open/Play Movie in FB5

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2010 : Group Archive : Group : All Groups

From: Eugen Rosu <eugen.rosu@...>
Date: Mon, 1 Nov 2010 16:30:05 +0200
Robert,
I'll write the files Bellow:

The MoviePlayer for FB4:
'--------------------------------
// === Globals  
====================================================================

_mFile        = 1
_iOpenCont    = 1
_iCloseMovie  = 2
_iQuit        = 4

_mEdit        = 2

_mOptions     = 3
_iPlay        = 1
_iStop        = 2
_iSlow        = 3
_iFast        = 4
_iLoop        = 5
_iBeep        = 6

DIM gMovieBlk&
DIM gQuit%

_FBQTMaxMoviesWnd  = 32
_EditSelectAll1    = 7
_EditSelectAll     = 8
begin RECORD MovieInfo
DIM MovieH    as handle
DIM MovieController&
DIM MoviePort as pointer
DIM MovieResRefNum%
END RECORD

END GLOBALS




'~Enter/Init this QT .Incl
LOCAL MODE
LOCAL FN FBQTEnter
IF FN ENTERMOVIES then shutdown "QuickTime Not Available!"
END FN = FN NEWPTRclear (sizeof(MovieInfo)*_FBQTMaxMoviesWnd_plus1)

'~Start a movie playing
LOCAL MODE
DIM OSErr%
dim @ DoActionResult&
LOCAL FN FBQTChgMovie (MovieBlk as pointer to  
MovieInfo,doWhat&,WhatInfo&)
long if MovieBlk
DoActionResult& = WhatInfo&
MovieBlk = MovieBlk + SIZEOF(MovieInfo) * WINDOW(_outputWnd)
OSErr% = FN MCDoAction(MovieBlk.MovieController&, doWhat&,  
#DoActionResult&)
end if
END FN


'~Set Up QT Edit Menu
local mode
dim mHndl&,ignore
local fn FBQTFixEditMenu(MovieBlk as pointer to MovieInfo,theKeys&)
mHndl& = fn getmhandle(_mEdit)
long if MovieBlk
MovieBlk = MovieBlk + SIZEOF(MovieInfo) * WINDOW(_ActiveWnd)
mHndl& = fn getmhandle(_mEdit)
ignore = FN MCSetUpEditMenu(MovieBlk.MovieController&,theKeys&,mHndl&)
xelse
call disableitem(mHndl&,_EditUndoItem) : call  
disableitem(mHndl&,_EditPasteItem)
call disableitem(mHndl&,_EditCutItem)  : call  
disableitem(mHndl&,_EditCopyItem)
call disableitem(mHndl&,_EditClearItem)
end if
end fn

'~Open a new QT Movie/Window
CLEAR LOCAL MODE
DIM ParamBlock.128,MovieCT&,OSErr%,WndID%,ResName$
dim @MovieResRefNum%,ResID%,DateRefChanged%
dim @ Movie&
dim @ CGrafPtr&,CurDev&
DIM @ FSSpec;0,FSVRefNum%,FSParID&,63 FSName$
DIM BoxRect as rect
LOCAL FN FBQTOpen(MovieBlk as pointer to MovieInfo,FileName$,VRefNum 
%,MovieTop%,MovieLeft%)

#if def _oneQTwindow
WndID% = _oneQTwindow
#else
DO
MovieBlk = MovieBlk + SIZEOF(MovieInfo)
INC(WndID%)
UNTIL WINDOW(-WndID%) = 0
#endif

long if WndID% <= _FBQTMaxMoviesWnd
FSVRefNum% = VRefNum%
FSName$    = FileName$
LONG IF MovieBlk
LONG IF FSName$ = ""'---> Try to Load Movie
FSName$ = FILES$(_fOpenPreview,"",,FSVRefNum%)
END IF
'
LONG IF FSName$ <> ""
#If CarbonLib
FSParID& = 0
Fn FBFixDirAndVol(FSVRefNum%,FSParID&)
OSErr% = Fn FSMakeFSSpec(FSVRefNum%,FSParID&,FSName$,FSSpec)
#Else
ParamBlock.ioNamePtr&   = @FSName$'nom du fichier
ParamBlock.ioVRefNum%   = FSVRefNum%'vol ref num
ParamBlock.ioFDirIndex% = 0'frapeau indiquant d'utiliser les nom & vRef
OSErr% = Fn GetCatInfo(ParamBlock)'lit les infos du fichier animation
'
FSParID& = [@ParamBlock + _ioFLParID]'parent ID ce dont nous avons  
besoin
#Endif'---> Open Movie
LONG IF FN OPENMOVIEFILE(FSSpec,MovieResRefNum%,_FSRdPerm) = _NoErr
LONG IF FN NEWMOVIEFROMFILE(Movie&,MovieResRefNum%,ResID%,ResName$, 
1,DateRefChanged%) = _noErr
CALL GETMOVIEBOX(Movie&,BoxRect)'---> Set Movie Rectangle
CALL OFFSETRECT(BoxRect,-BoxRect.Left%,-BoxRect.Top%)'---> Reset Movie  
Box
print BoxRect,-BoxRect.Left%,-BoxRect.Top% : delay 2000
CALL SETMOVIEBOX(Movie&,BoxRect)
WINDOW -WndID%,FSName$,(9000,9000)- 
(9100,9100),_DocNoGrow_updateVisRgn'build the window
window output -WndID%
CALL GETGWORLD(CGrafPtr&,CurDev&)
CALL SETMOVIEGWORLD(Movie&,CGrafPtr&,CurDev&)
MovieCT& = FN NEWMOVIECONTROLLER(Movie&,BoxRect,&15)'---> Get Movie  
Controls
OSErr%   = FN MCGetControllerBoundsRect(MovieCT&,BoxRect)
OSErr%   = FN MCEnableEditing(MovieCT&,_zTrue)
BoxRect.top% = 0 : BoxRect.left% = 0'Fix Top Left
call offsetrect(BoxRect,WndID%*16-8,WndID%*16+30)'Move Window on screen
WINDOW -WndID%,,@BoxRect : WINDOW WndID%
'---> Set Movie Block
MovieBlk.MovieH           = Movie&
MovieBlk.MovieController& = MovieCT&
MovieBlk.MoviePort        = CGrafPtr&
MovieBlk.MovieResRefNum%  = MovieResRefNum%
end if
END IF
END IF
END IF
xelse
WndID% = 0
END IF
END FN = WndID%

'~Give QT all the events it needs...
LOCAL MODE
DIM WndID%
dim @ OldPort&
LOCAL FN FBQTEvent(MovieBlk as pointer to MovieInfo, EventPtr&)
LONG IF MovieBlk
CALL GETPORT(OldPort&)
FOR WndID% = 1 TO _FBQTMaxMoviesWnd
MovieBlk = MovieBlk + SIZEOF(MovieInfo)
LONG IF MovieBlk.MovieH'---> Try Event
CALL SETPORT(MovieBlk.MoviePort)'---> Set To Window
LONG IF fn MCISPLAYEREVENT(MovieBlk.MovieController&,#EventPtr&)
EventPtr&.EvtNum% = 0'Handled by controller
END IF
END IF
NEXT WndID%
CALL SETPORT(OldPort&)
END IF
END FN

'~Close/Dispose of a QT Movie/Window
LOCAL MODE
DIM Movie&,OSErr%
LOCAL FN FBQTClose(MovieBlk as pointer to MovieInfo,WndID%)
long if MovieBlk
#if def _oneQTwindow
MovieBlk = MovieBlk + WndID%
#else
MovieBlk = MovieBlk + WndID% * SIZEOF(MovieInfo)
#endif
Movie&   = MovieBlk.MovieH
LONG IF Movie&
CALL StopMovie(Movie&)'stop the movie
CALL DISPOSEMOVIECONTROLLER(MovieBlk.MovieController&)
MovieBlk.MovieController& = 0
OSErr% = FN CLOSEMOVIEFILE(MovieBlk.MovieResRefNum%)'close the movie  
file
CALL DISPOSEMOVIE(MovieBlk.MovieH)
MovieBlk.MovieH = 0
WINDOW CLOSE WndID%
END IF
end if
END FN

'~Shut down all windows and QT
LOCAL MODE
DIM WndID%
LOCAL FN FBQTExit(MovieBlk as pointer to MovieInfo)
LONG IF MovieBlk
FOR WndID% = 1 TO _FBQTMaxMoviesWnd
FN FBQTClose(MovieBlk,WndID%)
NEXT WndID%
CALL EXITMOVIES
call DISPOSePtR(MovieBlk)
MovieBlk = 0
END IF
END FN = MovieBlk
'~ --- The End ---



'~'
width _NoTextWrap

'~Special Events come here
LOCAL FN doDialog
DIM DlgEV%,DlgID%
DlgEV% = DIALOG(0)
DlgID% = DIALOG(DlgEV%)
SELECT DlgEV%
CASE _WndClick : IF DlgID% THEN WINDOW #DlgID%
CASE _WndClose : FN FBQTClose(gMovieBlk&,DlgID%)
case _Preview
if DlgID%=_PreMenuClick then fn FBQTFixEditMenu(gMovieBlk&,gFBEvtMod%)
END SELECT
END FN

'~Menu's Come Here
LOCAL FN doMenu
DIM MenuID%,ItemID%
MenuID% = MENU(_menuID) : ItemID% = MENU(_itemID)
SELECT MenuID%'---> Handle Menu Selections
CASE _AppleResMenu     : ItemID% = fn Alert(128,0)
CASE _mFile
SELECT ItemID%
CASE _iOpenCont     : FN FBQTOpen(gMovieBlk&,"",0,0,0)'Open Movie
CASE _iCloseMovie   : FN FBQTClose(gMovieBlk&,WINDOW(_ActiveWnd))
CASE _iQuit         : end
END SELECT
CASE _mOptions
SELECT ItemID%
CASE _iPlay  : FN FBQTChgMovie(gMovieBlk&,_mcActionPlay, 
0x00010000)'Play Movie
CASE _iStop  : FN FBQTChgMovie(gMovieBlk&,_mcActionPlay, 
0x00000000)'Stop Movie
CASE _iSlow  : FN FBQTChgMovie(gMovieBlk&,_mcActionPlay, 
0x00008000)'Play Movie 1/2 speed
CASE _iFast  : FN FBQTChgMovie(gMovieBlk&,_mcActionPlay, 
0x00020000)'Play Movie 2x  speed
CASE _iLoop  : FN FBQTChgMovie(gMovieBlk&,_mcActionSetLooping,-1)'Play  
Movie
CASE _iBeep  : beep
END SELECT
print MenuID%, ItemID%
END SELECT
MENU
END FN

LOCAL FN InitializareMeniuri
Apple Menu "About MacSubtitler" '+ _kExampleName$
Menu _mFile, 0,_enable,"File"
Menu _mFile, _iOpenCont,_enable, "Open/O"
Menu _mFile, _iCloseMovie,_enable, "Close/W"
Menu _mFile, _iQuit,_enable, "Quit/Q"
END FN


'~Last Chance to Clean Up
local fn doStop
gMovieBlk& = FN FBQTExit (gMovieBlk&)
end fn

'~Main Program
gMovieBlk& = FN FBQTEnter// Init QT Include
FN InitializareMeniuri

'~Tell FB3 where to go!
ON DIALOG FN doDialog
ON MENU   FN doMenu
ON stop   FN doStop
ON EVENT  FN FBQTEvent(gMovieBlk&,EVENT)// Give QT all events
WINDOW 2

'~Loop til done...
while _zTrue
HANDLEEVENTS
wend

'--------------------------------------------


The MoviePlayer for FB5:


'--------------------------------
INCLUDE "Tlbx QuickTime.incl"

// === Globals  
====================================================================

_mFile        = 1
_iOpenCont    = 1
_iCloseMovie  = 2
_iQuit        = 4

_mEdit        = 2

_mOptions     = 3
_iPlay        = 1
_iStop        = 2
_iSlow        = 3
_iFast        = 4
_iLoop        = 5
_iBeep        = 6

DIM gMovieBlk&
DIM gQuit%

_FBQTMaxMoviesWnd  = 32
_EditSelectAll1    = 7
_EditSelectAll     = 8
begin RECORD MovieInfo
DIM as handle MovieH
DIM MovieController&
'DIM MovieController as ComponentInstance
DIM as pointer MoviePort
DIM as short MovieResRefNum
END RECORD

END GLOBALS




'~Enter/Init this QT .Incl
LOCAL MODE
LOCAL FN FBQTEnter
IF FN EnterMovies THEN ShutDown "QuickTime Not Available!"
END FN = FN NewPTRclear ( SizeOf( MovieInfo )*_FBQTMaxMoviesWnd_plus1 )

'~Start a movie playing
LOCAL MODE
      DIM as short OSErr
      DIM @ DoActionResult&
LOCAL FN FBQTChgMovie ( MovieBlk as pointer to MovieInfo, doWhat&,  
WhatInfo& )
long if MovieBlk
DoActionResult& = WhatInfo&
MovieBlk = MovieBlk + SIZEOF(MovieInfo) * WINDOW(_outputWnd)
OSErr = FN MCDoAction(MovieBlk.MovieController&, doWhat&,  
#DoActionResult&)
end if
END FN


'~Set Up QT Edit Menu
LOCAL
      dim as OSStatus ignore
      dim as MenuRef mHndl
local fn FBQTFixEditMenu( MovieBlk as pointer to MovieInfo, theKeys& )
mHndl = fn GetMenuHandle( _mEdit )
long if MovieBlk
MovieBlk = MovieBlk + SIZEOF( MovieInfo ) * WINDOW( _ActiveWnd )
mHndl = fn GetMenuHandle( _mEdit )
ignore = FN MCSetUpEditMenu( MovieBlk.MovieController&, theKeys&,  
mHndl )
xelse
call DisableMenuItem( mHndl, _kHICommandUndo )
call DisableMenuItem( mHndl, _kHICommandPaste )
call DisableMenuItem( mHndl, _kHICommandCut )
call DisableMenuItem( mHndl, _kHICommandCopy )
call DisableMenuItem( mHndl, _kHICommandClear )
end if
end fn

'~Open a new QT Movie/Window
CLEAR LOCAL MODE
DIM ParamBlock.128', MovieCT&
DIM as Str255 ResName
DIM as short MovieResRefNum, WndID, ResID, DateRefChanged
'dim @ MovieResRefNum%, , DateRefChanged%
'dim @ Movie&
'dim as handle Movie, MovieCT
dim as movie Movie, MovieCT
dim @ CGrafPtr&, CurDev&
'DIM @ FSVRefNum%, FSParID&

DIM as rect BoxRect

dim as Str63    FSName
dim as FSSpec   fileSpec, FSSpec
dim as OSStatus    err
LOCAL FN FBQTOpen( MovieBlk as pointer to MovieInfo, FileName as  
Str255, VRefNum as short, MovieTop as short, MovieLeft as short)

#if def _oneQTwindow
WndID = _oneQTwindow
#else
DO
MovieBlk = MovieBlk + SIZEOF( MovieInfo )
INC( WndID )
UNTIL WINDOW( -WndID ) = 0
#endif

long if WndID <= _FBQTMaxMoviesWnd
'FSVRefNum% = VRefNum%
FSName    = FileName
LONG IF MovieBlk
LONG IF FSName = ""'---> Try to Load Movie
FSName = files$( _FSSpecOpen,, "Open Movie:", fileSpec )
END IF
'
LONG IF FSName <> ""
'#If CarbonLib

'FSParID& = 0
'Fn FBFixDirAndVol( FSVRefNum%, FSParID& )
'err = Fn FSMakeFSSpec(FSVRefNum%, FSParID&, FSName, FSSpec )
'#Else

'ParamBlock.ioNamePtr&   = @FSName'nom du fichier
'ParamBlock.ioVRefNum%   = FSVRefNum%'vol ref num
'ParamBlock.ioFDirIndex% = 0'frapeau indiquant d'utiliser les nom & vRef
'err = Fn GetCatInfo( ParamBlock )'lit les infos du fichier animation
'
'FSParID& = [@ParamBlock + _ioFLParID]'parent ID ce dont nous avons  
besoin
'#Endif'---> Open Movie
LONG IF FN OpenMovieFile( fileSpec, MovieResRefNum, _FSRdPerm ) = _NoErr
LONG IF FN NewMovieFromFile( Movie, MovieResRefNum, ResID, ResName, 1,  
DateRefChanged)  = _noErr
CALL GetMovieBox( Movie, BoxRect )'---> Set Movie Rectangle
CALL OffSetRect( BoxRect, -BoxRect.Left, -BoxRect.Top )'---> Reset  
Movie Box
CALL SetMovieBox( Movie, BoxRect )
'WINDOW -WndID%, FSName, ( 9000,9000 )- 
( 9100,9100) ,_DocNoGrow_updateVisRgn'build the window
WINDOW -WndID%, FSName, BoxRect ,_DocNoGrow_updateVisRgn'build the  
window
WINDOW OUTPUT -WndID
'CALL GetGWorld( CGrafPtr&, CurDev& )
CALL GetMovieGWorld( Movie, CGrafPtr&, CurDev&)
CALL SetMovieGWorld( Movie, CGrafPtr&, CurDev&)
MovieCT = FN NewMovieController( Movie, BoxRect, &15 )'---> Get Movie  
Controls
err   = FN MCGetControllerBoundsRect( MovieCT, BoxRect )
err   = FN MCEnableEditing( MovieCT, _zTrue )
BoxRect.top = 0 : BoxRect.left = 0'Fix Top Left
call OffSetRect( BoxRect, WndID*16-8, WndID*16+30 )'Move Window on  
screen
WINDOW -WndID, , BoxRect : WINDOW WndID
'---> Set Movie Block
MovieBlk.MovieH           = Movie
MovieBlk.MovieController& = MovieCT
MovieBlk.MoviePort        = CGrafPtr&
MovieBlk.MovieResRefNum%  = MovieResRefNum
end if
END IF
END IF
END IF
xelse
WndID = 0
END IF
END FN = WndID

'~Give QT all the events it needs...
LOCAL MODE
      DIM as short WndID
      dim @ OldPort&
LOCAL FN FBQTEvent( MovieBlk as pointer to MovieInfo, EventPtr& )

LONG IF MovieBlk
CALL GetPort( OldPort& )
FOR WndID = 1 TO _FBQTMaxMoviesWnd
MovieBlk = MovieBlk + SizeOf( MovieInfo )
LONG IF MovieBlk.MovieH'---> Try Event
CALL SetPort( MovieBlk.MoviePort )'---> Set To Window
LONG IF fn MCISPlayerEvent( MovieBlk.MovieController&, #EventPtr& )
EventPtr&.EvtNum = 0'Handled by controller
END IF
END IF
NEXT WndID
CALL SETPORT( OldPort& )
END IF
END FN

'~Close/Dispose of a QT Movie/Window
LOCAL MODE
      DIM as handle Movie
      dim as OSStatus    err
LOCAL FN FBQTClose( MovieBlk as pointer to MovieInfo, WndID as short )
long if MovieBlk
#if def _oneQTwindow
MovieBlk = MovieBlk + WndID
#else
MovieBlk = MovieBlk + WndID * SIZEOF( MovieInfo )
#endif
Movie   = MovieBlk.MovieH
LONG IF Movie
CALL StopMovie( Movie )'stop the movie
CALL DisposeMovieController( MovieBlk.MovieController& )
MovieBlk.MovieController& = 0
err = FN CloseMovieFile(MovieBlk.MovieResRefNum%)'close the movie file
CALL DisposeMovie( MovieBlk.MovieH )
MovieBlk.MovieH = 0
WINDOW CLOSE WndID
END IF
end if
END FN

'~Shut down all windows and QT
LOCAL MODE
      DIM as short WndID
LOCAL FN FBQTExit( MovieBlk as pointer to MovieInfo )
LONG IF MovieBlk
FOR WndID = 1 TO _FBQTMaxMoviesWnd
FN FBQTClose( MovieBlk, WndID )
NEXT WndID
CALL ExitMovies
call DisposePtr( MovieBlk )
MovieBlk = 0
END IF
END FN = MovieBlk
'~ --- The End ---



'~'
width _NoTextWrap

'~Special Events come here
LOCAL
      DIM as short DlgEV, DlgID
LOCAL FN doDialog
DlgEV = DIALOG( 0 )
DlgID = DIALOG( DlgEV )
SELECT DlgEV
'CASE _WndClick : IF DlgID% THEN WINDOW #DlgID%
CASE _WndClose : FN FBQTClose( gMovieBlk&, DlgID )
CASE _Preview
'IF DlgID% = _PreMenuClick THEN FN FBQTFixEditMenu( gMovieBlk&,  
gFBEvtMod% )
END SELECT
END FN

'~Menu's Come Here
LOCAL
      DIM as short MenuID, ItemID
LOCAL FN doMenu
MenuID = MENU( _menuID ) : ItemID = MENU( _itemID )
SELECT MenuID'---> Handle Menu Selections
CASE _AppleResMenu     : ItemID = fn Alert( 128, 0)
CASE _mFile
SELECT ItemID
CASE _iOpenCont     : FN FBQTOpen( gMovieBlk&, "", 0, 0, 0 )'Open Movie
CASE _iCloseMovie   : FN FBQTClose( gMovieBlk&, WINDOW( _ActiveWnd ))
CASE _iQuit         : END
END SELECT
CASE _mOptions
SELECT ItemID
CASE _iPlay  : FN FBQTChgMovie( gMovieBlk&, _mcActionPlay, 0x00010000)  
'Play Movie
CASE _iStop  : FN FBQTChgMovie( gMovieBlk&, _mcActionPlay,  
0x00000000 )'Stop Movie
CASE _iSlow  : FN FBQTChgMovie( gMovieBlk&, _mcActionPlay,  
0x00008000 )'Play Movie 1/2 speed
CASE _iFast  : FN FBQTChgMovie( gMovieBlk&, _mcActionPlay, 0x00020000)  
'Play Movie 2x  speed
CASE _iLoop  : FN FBQTChgMovie( gMovieBlk&, _mcActionSetLooping,  
-1 )'Play Movie
CASE _iBeep  : beep
END SELECT
print MenuID, ItemID
END SELECT
MENU
END FN

LOCAL FN InitializareMeniuri
Apple Menu "About MacSubtitler" '+ _kExampleName$
Menu _mFile, 0,_enable,"File"
Menu _mFile, _iOpenCont,_enable, "Open/O"
Menu _mFile, _iCloseMovie,_enable, "Close/W"
Menu _mFile, _iQuit,_enable, "Quit/Q"
END FN


'~Last Chance to Clean Up
local fn doStop
gMovieBlk& = FN FBQTExit ( gMovieBlk&)
end fn

'~Main Program
gMovieBlk& = FN FBQTEnter// Init QT Include
FN InitializareMeniuri
window 2

'~Tell FB3 where to go!
ON DIALOG FN doDialog
ON MENU   FN doMenu
'ON STOP   FN doStop
'ON EVENT  FN FBQTEvent( gMovieBlk&, EVENT )// Give QT all events

'~Loop til done...
while _zTrue
HANDLEEVENTS
wend
'--------------------------------

Thanks