Playing Window media control in Access 2000 (1 Viewer)

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
I am a newbie to access programming. currently working on a project whereby I
need to insert .wma file into my form through window media player control by
writing coding in VB editor. seems like there isnt much help from web sites
and reference books regarding this topis. hopefully someone can be kind &
merciful enough to help or guide me.. Thanks a lot in advance. God Bless:)
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 21:35
Joined
Jan 31, 2008
Messages
585
Here is a small sample with a few lines of code to get you started.

The Windows Media Player control is used here. When the Sample starts, it should play when you select the Play Button. If it doesn't then locate a wma file of your own and place the path into the wmp.url string located within the Form's OnOpen event.

.
 

Attachments

  • AccessMediaPlay.zip
    13 KB · Views: 1,902

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
Error Playing file extension

thanks for replying..
however, I try below code:

Dim wmdpAs WindowsMediaPlayer
Set wmdp= CreateObject("WMPlayer.ocx.7")
wmdp.url = "file.wma"
wmdp.play

Error Display >> Windows Media Player cannot find the specified file. Be sure the path is typed correctly. If it is, the file does not exist at the specified location, or the computer where the file is stored is offline.

I check my .wma file extension but its correct.
I right click on my media player control> properties file extension is right.
Or should i try to
>> mymediaplayercontrol = wmdp ??
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 21:35
Joined
Jan 31, 2008
Messages
585
The Error displayed to you is indeed correct in this case. You did not specify a Path to the file file.wma. Yes, you specified the file name but you did not tell the media player where to find the file.

If the file.wma file is located in the Root directory of Hard Disk Drive C then the Media Player control needs to be told that. For example:

wmdp.url = "C:\file.wma"

If the file.wma file is located in the same location where your MS-Access Database is located (the database running this code) then you need to tell the Media Player that as well by using this sort of method:

wmdp.url = Application.CurrentProject.Path & "\file.wma"

The Application.CurrentProject.Path is a internal Microsoft Access property that returns the Path location of the Database (your database) which queried it. For example, if your Database name is MyDB.mdb and it was located on Hard Disk Drive E: in the Folder named MyDatabases then the Application.CurrentProject.Path property will provide this when used:

E:\MyDatabases (no backslash at the end)

If you wanted the Path and File Name of your running Database then you could use:

Application.CurrentProject.FullName

Try it: MSgBox Application.CurrentProject.FullName

this will return in a Message Box the Path and File Name of your running Database. In the case of our example this would be:

E:\MyDatabases\MyDB.mdb

If you just want the running Database File Name then you can use:

Application.CurrentProject.Name

Bottom line....you need to tell the Media Player control exactly where to find the file to play.

Another thing you should be aware of is, when you provide the Url to the Media Player Control as in:

wmdp.url = "C:\file.wma"

the Media Player will automatically start to play the file. You do not need the wmdp.play which for clarity should really be in your case, wmdp.Controls.Play.

I had provided you with a simple sample that demonstrates all the above items mentioned....please look at the code a little closer. Try to understand it just a little bit more. You will benefit by doing so in the future should you ever need to look back upon your code.

Good luck with your project.

.
 

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
Error Again *Sign*

Hi CyberLynx:

1) Had heed your advice, but still not working:(
2) I copy my file (.wma) to desktop & try to paste it to your code.
3) What your program does was pop out a message and state the file name., I cant view the video clips at all.. :( *sign*

Code as follows : Wmp.URL = "C:\Documents and Settings\edisonl\Desktop\redridinghood.wma"

Qs: Do I need to insert window media player control from Activex ?
Had appreciate your quick respond anyway. :)
 

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
I saw your windowmediaplayer1 control. but they isnt any code tied to it nor playing any animation. does it have any significance?
 

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
Setting Required

Do I need to do any setting adjustments on my access 2000 or VB editor or other location like system, windows... etc etc.. to enable window media player control ?
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 21:35
Joined
Jan 31, 2008
Messages
585
Hi edisonl,

We first need to clarify something here. In your first post you indicated that you wanted to play a .wma file in your Form. To make sure one thing is clear here, a WMA file is a Audio file. WMA stands for Windows Media Audio. The sample DB's provided will play those files but now I am getting the impression that what you really want to do is display Video files as in video clips etc.

Which is it?....Both?

To play Audio files you do not need to place the Media Control itself into your Form but you do need to Reference the Window Media Player OCX through the References Window located within the VBA IDE (VBA Code Editor). When in the Code Editor, simply select the Tools Menu then select References. Scroll down the list of different references until you see the Windows Media Player reference (near the bottom). Make sure you Check Mark it then select the OK button to exit the References Window.

With reference to the Windows Media Player now in place, to merely play an audio file (wma, wav, mp3, etc) when yourForm opens up you only really need three lines of code:

Dim Wmp As WindowsMediaPlayer
Set Wmp = CreateObject("WMPlayer.OCX.7")
Wmp.URL = "C:\WINDOWS\SYSTEM32\oobe\images\title.wma"

You can place this into the Form's OnOpen event. When the Form opens then music starts to place. (I like the title.wma song...it sounds nice).

To play Video files is quite a bit different and can get quite in depth especially if you are trying to play Video using your own Command buttons etc. and not the controls attached to the Windows Media Player control itself. This would be a daunting task (to say the least) for a novice to VBA to carry through.

To play Video files, you need to actually place the Windows Media Player control into your Form (from the More Tools button). Then control the Media Player by referencing it directly as in WindowsMediaPlayer1.Url = "C:\MyVideo.wmv" and so on. The Windows Media Player control is an in-depth and complicated control and a lot of learning will be need to be done before taking full advantage of this ActiveX control.

Attached is a simple sample of the Windows Media Player control in a Microsoft Access Form for playing Video or Audio media of all kinds. The few lines of code are well commented.

You will need to ensure you have references to the Microsoft 10 Object Library and the Windows Media Player. If you have these or better they will automatically be referenced.

Good luck with your Project.
 

Attachments

  • AccessMediaPlayer.zip
    17.6 KB · Views: 925

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
How to Auto-Run Window Media Player in VBA ?

1) Well.. apparently you are right. I am playing a video file.
sorry for the misunderstanding. :p

2) Guess I almost give up that function if not I saw your reply.

3) As I check my VBA> Tools> References It doesnt have Microsoft 10 Object Library .

4) Eg: If my file Path: "c:\01.wma"

5) In your program where should I place it.

6) Base on the structure of my program, I am playing an Auto-Run clips(.wma) base on recordset choose by user.

7) Is there a way to do an auto run of the window media control in my form through VBA ?


Chhers & God Bless
 

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
HOW (SET Windows Media Player.Play)?

In Access 2000,

- How to set my Windows Media Player Control to play my video (01.wma) file?

- I have table consist of all link to my video files.

- So I set
windowmediaplyaer1. url = [forms]![movietable]![Link]

- So my questions is : How to activate the player ?

- I set my VBA references> Microsoft Office10.0 .Library ,
Microsoft Access 10.0 Library @ home.

- If my company's system doesn't have above mention references, where can I download it ?

Cheers & God Bless ;)
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 21:35
Joined
Jan 31, 2008
Messages
585
Oh dear.....don't give up yet edisonl. That would be far to easy and nothing is really gained from it it.

It's no secret, the Windows Media Player is not a easy one to master. The Control is extensive and relatively flexible for all sorts of things. It's all a matter of how deep of a hole do you want to dig to accomplish your task. To use the Windows Media Player within your application is not for the weak at heart.

So... you want to have a Database (naturally) which will contain a Table or tables that would of course store the location of specific media files, and you want to view these media files while navigating through the table records.

Sure, why not. Attached to this post is a Sample DB that does exactly that. But not just Video and Music media, Image media as well. Contrary to popular belief, the Windows Media Player will also display Image files like BMP, JPG, PNG, etc., etc.

Now, do keep in mind. I whipped up this sample pretty quick so don't expect the Sun to shine from it. It took me longer to comment the code than it did to create this simple MS-Access Media Player. Thankfully, the Windows Media Control does all the work. As I said...the code is well commented to you can see how things work and what does what. This sample also has done away with the Microsoft Office 10 Object Library reference since you have mentioned that you are having problems with the reference (which is why I like to stay away from them to begin with).

The Microsoft Office 10 Object Library was merely used for simplicity in generating the File Browser Dialog window and I mentioned earlier, is now no longer needed. A Windows API File Browser Dialog window now takes its place.

Now to your Questions:

As I check my VBA> Tools> References It doesnt have Microsoft 10 Object Library

When you have the references window open, scroll down the List until you see it. When you do, check mark it then select the OK button. If you do not have it within the References list then update you MS-Office through Windows Update services.

Eg: If my file Path: "c:\01.wma". In your program where should I place it.

In the last sample I provided you merely need to click on the Load button, when the File Browser Dialog is displayed just navigate to drive C: and select your file. If you can not Use the File Browser then you will need to go into the Code in the OnClick event for the Load button. The very last line of the procedure is the one of concern:

If Len(Strg) > 0 Then Me.WindowsMediaPlayer1.URL = Trim(Strg)

To play just the one file....remove everything within that procedure except this one line:

Me.WindowsMediaPlayer1.URL = "c:\01.wma"

so the complete event procedure should look like this:

Code:
Private Sub LoadFileBut_Click()
   Me.WindowsMediaPlayer1.URL = "c:\01.wma"
End Sub

Now, when you click the Load button the 01.wma audio will play.


Base on the structure of my program, I am playing an Auto-Run clips(.wma) base on recordset choose by user. Is there a way to do an auto run of the window media control in my form through VBA ?

Yes....See the attached Sample DB. The code is extensively commented so you can see how to do it. It's all a matter of filling the Windows Media Player Url within the Form's OnCurrent event.

How to set my Windows Media Player Control to play my video (01.wma) file?

I think I've already sufficiently answered that question.

- I have table consist of all link to my video files. - So I set windowsmediaplayer1.url = [forms]![movietable]![Link]. So my questions is : How to activate the player ?

Basically, Yes within the OnCurrent event of your Form.

I set my VBA references> Microsoft Office10.0 .Library ,
Microsoft Access 10.0 Library @ home. - If my company's system doesn't have above mention references, where can I download it ?

Upgrade MS-Office from Microsoft through the Windows Update Services. As I mentioned earlier...this current sample has done away with the Library reference.

Other things to take note about. To use the Windows Media Player Control you do not need to reference it in the VBA IDE if you place the Control onto your Form. The Reference is for access to the wmp.dll which allows for remote operation of the Media Player.

I Hope this sample helps you. If anything, it should keep you busy for a while ;)

.
 

Attachments

  • AccessMediaPlay3.zip
    65.9 KB · Views: 1,035

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
Sorry, Yes !

Sorry_Click()
Dim CyberLynx.. I manage to solve it at last ! !! :D as Friend

Sorry not for the fact of your part but I felt I ought to get a slap onmy face. Indeed, it is stupid mistake, for my table does not save the right file extension.

Right one should be .wmv ! NOT WMA !!! I check with the file name by opening up windows media player and check properties of the file!

So when I change all file extension back to .wmv it works like a clock man!

Thanks so much for all your effort, CyberLynx! Appreciate it. I didnt change much of the Object.Library stuff leaving it on version 9 as I was told that my program would be running on another person work station it will be much hasle to do update. I like to thank you for your encouragement as well.

Right now just felt like had cross a marathon finishing line. Tired & a sense of achievement. Still need to do some presentation & documentation for the management. *Phewz

What I did just like what you suggest:

myplayer.url = [forms]! [form]! [subform]![fieldname] 'Thats All

Much regret I embarass myself as well as wasting your time.

Hope to keep in touch, as I was told there is another project coming up for me for Excel Programing in which much in depth I need to import all those files
in the table and do comparison in acces ! *Duh! *Faint

ThanksOnceAgain_Click
God_Bless
Exit Sub :p
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 21:35
Joined
Jan 31, 2008
Messages
585
haha...I am glad for you that it all worked out edisonl. :)

It's like I mentioned in a earlier post, the .wma extension is a Windows audio file created by Microsoft in competition towards another audio format. Microsoft obviously lost the battle. ;) Media Player will of course play the .wma audio files.

I think I should also mention that I forgot to place a very important file extension for the File Browser Dialog filter in the previous Sample DB posted. That file extension is for the DIVX video (.divx) which is one of the more common video formats today. Simply add the extension to the Dialog Filter Variable or replace the Filter with this (copy/paste):
Code:
StrgFilter = "All Media Files (*.*)" & Chr$(0) & "*.avi;*.asf;*.asx;*.wax;" & _
             "*.wvx;*.wpl;*.wm;*.wma;*.wmd;*.wav;*.wmv;*.wmx;*.mp3;*.mpg;" & _
             "*.mpeg;*.m1v;*.mp2;*.mpa;*.mpe;*.mpv2;*.m3u;*.mid;*.midi;" & _
             "*.rmi;*.aif;*.aifc;*.divx;*.au;*.cda;*.ivf;*.mov;*.qt;" & _
             "*.bmp;*.jpg;*.wmf;*.emf;*.dib;*.gif;*.png;*.tif" & Chr$(0)

The StrgFilter variable is located within the MouseUp event for the Media Path button on Form. This Filter string above also has the .ico extension removed. Media Player will not display icons.

.
 

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
Extract String

Hi CyberLynx

1) I have Input from scanner 40 characters.
2) I have 2 text box
3) How do I put first 10 characters input into textbox1, while16th - 23th character input into textbox2 ?

Cheers & God Bless
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 21:35
Joined
Jan 31, 2008
Messages
585
This should have gone into a new Thread my friend. In any case:


Dim ScanStrg As String

ScanStrg = ScannerReturnString

'First 10 Characters:
Me.TextBox1 = Left$(ScanStrg, 10)

'16th to and including the 23rd Characters:
Me.TextBox2 = Mid$(ScanStrg, 16, 8)

'Or if you want to use Variables:
Dim Lower As Integer, Upper As Integer
Lower = 16
Upper = 23
Me.TextBox2 = Mid$(ScanStrg, Lower, (Upper - Lower) + 1)

.
 

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
It Works

Thanks, man. It works.

Regards & God Bless
 

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
It Works

Hi CyberLynx,

I tried it & it works !

PS: By the way, Do you have any good recommendation access 2000 programming books ?

:)(Thanks & God Bless)
 

edisonl

Registered User.
Local time
Yesterday, 21:35
Joined
Feb 24, 2008
Messages
41
Sorry for the late reply

Hi Cyber Lynx,

Thanks for the help so far. It all works well. Trying to solve a couple of small bugs here and there and looking for a spilitter thingy.

Regards & God Bless
 

anchamal

Registered User.
Local time
Yesterday, 21:35
Joined
Mar 7, 2010
Messages
57
doing something similar.
but i need to have add to playlist.

can you show me an example with the sample you already provide?
that will help me a lot.

(i'm using ms access 2013)

thanks
 

Users who are viewing this thread

Top Bottom