Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MCI player API does not recognize MP4 files

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
526
Brasil
Hello colleagues!

I have VFP9 application (using MCI player API) that plays AVI and MPG movies fine.

Today I installed the VLC player in my Windows XP computer, in order to play MP4 files. It works fine when I click on any MP4 file, inside Windows Explorer. But it is not operating inside my VFP application, which plays AVI & MPG files inside it normally. When I clicked the Load button inside the application I got the error:

"The specified device is not open, or MCI does not recognize it."

Of course I added MP4 extension in the VFP application.

Player opens and the movie is played normally.


Thank you,
SitesMasstec
 
Please show us the code you are trying to use to play the MP4s.

Also, what is the "Load" button you are referring to? Is it part of your own application, or of VCL? If the former, what is the code in its Click event?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
MCI could play mp4, provided the necessary codecs are installed and the video is intact. You might just have a wrongly encoded video. It can be just as simple as that.

Also associating any file extension with your own application does not mean you handle them.
You will need to handle DDE execution requests to your EXE when an open action on a mp4 file should call your EXE to play that video.
This needs a DDE interface like this:
Don't pay attention to the first sentence here, VFP can create OLE servers now since many years, but that won't help you with file associations at all anyway.

If you have some kind of file picking mechanism in your application to pick a mp4 file and play it, there's no need to associate it with the MP4 extension at all, you just need to populate a Listbox with ADIR results of the mp4 and other vide0 extensions or use GETFILE(). You would only associate your application with mp4 if your applications main intention is to play mp4 files. If this is just a feature aside of main features, Windows users don't like applications to register a file extension, which already is associated with other software, a video player in this case, and not with any other application, that's not mainly concerned with such files, because only one application per file extension is the standard, like with mail clients and browsers. Windows can know more than one application capable to handle some file, but only associate one with the open action.

Bye, Olaf.
 
Hello Mike!


Click code for Load movie button:

Code:
THIS.Enabled= .F.

*!* Check to make sure a media file is not already open
cCmd = ("STATUS FoxMedia READY")
IF THISFORM.doMCI(cCmd) = "true" THEN
	*!* If one is, close it
	cCMD = ("CLOSE FoxMedia WAIT")
	THISFORM.doMCI(cCmd)
	
	*!* And use the custom Disable method of the form to disable
	*!* all appropriate controls
	THISFORM.disable(.T.)
ENDIF

*!* Prompt the user for the media file to open
cFileName = "VIDEOREC\"+"R"+LTRIM(STR(YRCODI))+".MP4"     && era: cFileName = GETFILE("avi|mov|wav|mid","Select file to play")
 
SET COMPATIBLE ON
TamVideo=FSIZE(cFileName)/1024
SET COMPATIBLE OFF


IF !EMPTY(cFileName) THEN
	
	_SCREEN.MousePointer = 11
	THISFORM.lblLoading.visible = .T.

	* Returns Handle of Main VFP Window
	Main_hWnd =_VFP.hWnd
	
	* Get Handle of the form with FOXTOOLS.FLL
	cur_window = THISFORM.HWnd 
	
	NullPointer = 0
	
	*!* Set up open MCI command into string variable
	cCmd = ('OPEN "' + cFileName + '" alias FoxMedia' + ;
	  ' style child parent ' + ALLTRIM(STR(cur_window)) + ' WAIT')

	*!* Execute the MCI command
	THISFORM.doMCI(cCmd)

	*!* Check to see if MCI command succeeded
	IF THISFORM.MCIerror > 0 THEN
		*!* If not, it might be a non-visual media
		*!* We'll try to open it without setting the window parent
		cCmd = ('OPEN "' + cFileName + '" alias FoxMedia WAIT')
		THISFORM.doMCI(cCmd)
		IF THISFORM.MCIerror > 0 THEN
			*!* Nope, still won't open.  Some other error.  
			*!* Let's show the user the MCI error and get out
			messagebox(THISFORM.MCIerrorString)
			THISFORM.lblLoading.visible = .F.
			_SCREEN.MousePointer = 0
			RETURN
		ELSE
			*!* It's not a visual media, so let's show a label
			*!* to let the user know the media has been loaded
			THISFORM.lblNonVisual.visible = .T.
		ENDIF
	ELSE
		*!* It does have visual media, so we need to set up the window
		*!* it will play in.
		
		*!* Get the window handle of the window playing the video
		cCmd = "status FoxMedia window handle wait"
		hWin = INT(VAL(THISFORM.doMCI(cCmd)))
	
		*!* Once we have the window handle, we need to position
		*!* the video window to be the same position and size
		*!* as our player rectangle on the form
		x1Pos = THISFORM.player.LEFT
		y1Pos = THISFORM.player.TOP
		x2Pos = THISFORM.player.width
		y2pos = THISFORM.player.height

		*!* Use the SetWindowPos Windows function to set position and size
		setWindowPos(hWin,0,x1Pos,y1Pos,x2Pos,y2Pos,0)

		*!* Everything's done, let's show the video
		cCmd = ("WINDOW FoxMedia state show")
		THISFORM.doMCI(cCmd)

	ENDIF

	*!* Set the device to use milliseconds when setting/getting position
	THISFORM.doMCI("SET FoxMedia time format milliseconds")

	*!* Enable all appropriate controls
	THISFORM.disable(.F.)
	
	THISFORM.lblLoading.visible = .F.
	
	THISFORM.cmdPause.Enabled = .F.
	THISFORM.cmdStop.Enabled = .F.
	
	_SCREEN.MousePointer = 0
ENDIF


Click code for Play movie button:
Code:
THISFORM.cmdPause.Enabled = .T.
THISFORM.cmdStop.Enabled = .T.

*!* First need to see if the media is at the end 
*!* by comparing the total length with the current position
nMediaLength = VAL(THISFORM.doMCI("STATUS FoxMedia length"))
nMediaPosition = VAL(THISFORM.doMCI("STATUS FoxMedia position"))

IF nMediaPosition >= nMediaLength THEN
	*!* The media is at the end, so we need to seek back to the start
	*!* of the clip before playing
	THISFORM.doMCI("SEEK FoxMedia to start WAIT")
ENDIF

*!* Now we can play the media
THISFORM.doMCI("PLAY FoxMedia")
IF THISFORM.MCIerror > 0 THEN
	THISFORM.showMCIerror
ELSE
	THISFORM.timer1.interval = 360
ENDIF




Thank you,
SitesMasstec
 
What I spot missing is the check, whether the file is found. You also might still have it open for recording. You can't play back a file still open by another process recording it.

Bye, Olaf.
 

Hello Olaf!

In fact I have 3 Load buttons: one for AVI, one for MPG and onde for MP4 files.

The code showed above is for MP4 files.

The same code is used for Load buttons for AVI and MPG files. In those cases just extensions are changed (.AVI, .MPG). They are working fine for AVI and MPG files.








Thank you,
SitesMasstec
 
>alias FoxMedia

If all three buttons use the same alias name for the file opened, that won't work, but I still think the main problem is simply the file itself. You expect MCI commands to be able to play all videos VLC or Windows Media player can also play, but that's not the case.

Your code is pretty much copied from the Open button of Mci_play.scx, more precise:
Code:
MODIFY Form HOME()+'\Samples\Solution\Forms\Mci_play.scx'

I used this to open some MP4 file, but it won't play. VLC doesn't share its own MP4 codec to the Windows system.

Look at this short discussion:
Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top