Go Back   Access World Forums > Apps and Windows > Excel

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-23-2019, 10:17 AM   #31
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 3,673
Thanks: 398
Thanked 637 Times in 618 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: get details of song being played

Quote:
Originally Posted by smiler44 View Post
Am I right in thinking that the song title is known when the fileinfo function runs? In this new situation, I have not been able to acquire the title.
If you could help me get the title of the song being played by windows media player I'd appreciate it.

smiler44
You have it the wrong way round.
You tell WMP what to play, so at that point YOU know what the filename is.

__________________
Access novice. Sometimes trying to give something back.
Access 2007


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is online now   Reply With Quote
Old 05-23-2019, 10:27 AM   #32
June7
Newly Registered User
 
June7's Avatar
 
Join Date: Mar 2014
Posts: 1,960
Thanks: 0
Thanked 463 Times in 459 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: get details of song being played

Okay, see that function now. Doesn't appear RecursiveDir is even using the value passed to it.
__________________
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
June7 is online now   Reply With Quote
Old 05-23-2019, 10:29 AM   #33
smiler44
Newly Registered User
 
Join Date: Jul 2008
Location: UK
Posts: 637
Thanks: 13
Thanked 9 Times in 8 Posts
smiler44 is on a distinguished road
Re: get details of song being played

Quote:
Originally Posted by June7 View Post
As suggested, why don't you provide the workbook for analysis?

The FileInfo function requires file name to be passed to it as argument. Yet I don't see the function called. The sub randomlyselectsong has the file name. It sets the variable filetoplay and sends that value to the player. This is where you should put code to get the file duration, just before Shell command opening the file in player. Modify the code I provided. It can be a function with arguments or include the 3 lines of code within your procedure. Only instead of Debug.Print, set a variable.
I am just tabbing through the code to make sure what i provided was working, have you tried the code?

Are we getting out wires crossed? Ignoring the code i have provided can you help with using vba code to get the name of the song currently being played by windows media player?

smiler44

smiler44 is offline   Reply With Quote
Old 05-23-2019, 10:43 AM   #34
June7
Newly Registered User
 
June7's Avatar
 
Join Date: Mar 2014
Posts: 1,960
Thanks: 0
Thanked 463 Times in 459 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: get details of song being played

I am not interested in building workbook.

Already have the file name in sub randomlyselectsong. As I stated, put code there to pull duration.
__________________
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
June7 is online now   Reply With Quote
Old 05-23-2019, 10:46 AM   #35
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 3,673
Thanks: 398
Thanked 637 Times in 618 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: get details of song being played

June7,
I've tweaked my copy a little to try and understand how it worked.

The call to RecursiveDir I changed to use f as that is the folder for the files in RandomlySelect sub?

That sub then uses that, plus ftp (the filename) and the item number.

It is very haphazard, and smiler44 has explained why.

To be fair to get it working as it is now would have been a monumental task for smiler44, so fair play.
__________________
Access novice. Sometimes trying to give something back.
Access 2007


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is online now   Reply With Quote
Old 05-23-2019, 10:49 AM   #36
smiler44
Newly Registered User
 
Join Date: Jul 2008
Location: UK
Posts: 637
Thanks: 13
Thanked 9 Times in 8 Posts
smiler44 is on a distinguished road
Re: get details of song being played

Quote:
Originally Posted by smiler44 View Post
I am just tabbing through the code to make sure what i provided was working, have you tried the code?

Are we getting out wires crossed? Ignoring the code i have provided can you help with using vba code to get the name of the song currently being played by windows media player?

smiler44
this is the code that my existing project uses

Code:
Sub start()
' play music for pre determined time

Sheet1.Range("A1").Value = "00:00:00"
Sheet1.Range("A2").Value = "00:00:00"
Sheet1.TextBox2.Value = "00:00:00"

Call randomlyselectsong

If Sheet1.CheckBox1.Value = True Then ' shutdown laptop
Call shutdown 'shut down laptop
End If
'MsgBox ("finished")
End Sub

Dim fs, f1, fc, s
Dim ftp
Dim b 'amount of time to pause for while song plays
'other wise next song play immediately


'used with randum play for set time module



Public Sub randomlyselectsong()

Dim mm ' minutes
Dim ss ' seconds

Do Until Sheet1.TextBox2.Value > Sheet1.TextBox1.Value

Set fs = CreateObject("scripting.filesystemobject")

Set f = fs.GetFolder("C:\users\Dirk pitt\Documents\Dads Music")

Randomize
i = CInt((Rnd() * f.Files.Count) + 1)
j = 1
For Each fi In f.Files
If j = i Then

ftp = fi.Name 'fi, randomly selected song

Call RecursiveDir(Directory)

filetoplay = """C:\users\Dirk pitt\Documents\Dads Music\" & ftp
Shell "C:\Users\Dirk Pitt\Documents\wmplayer /play /close " & filetoplay

''''''''''''''''''''''''''''''''''''''''
   'Sheet1.TextBox2.Value = Range("a3").Text
   Range("a2").Value = Sheet1.TextBox2.Value 'time music played before current song
   Sheet1.TextBox2.Value = Range("a3").Text ' total time music played after current song
ss = Right(b, 2) ' gets far right 2 charectors

mm = Mid(b, 4, 2) 'starting at 4 from left, gets the 4th and 5th charector

b = mm * 60 + ss
          
pause (b) ' how long to wait in seconds before playing next song
'''''''''''''''''''''''''''''''''''''''''
End If
j = j + 1
Next

Loop
End Sub

Public Sub RecursiveDir(ByVal currdir As String)

  Range("A1").Select
  Range("a1").Value = FileInfo("C:\Users\Dirk Pitt\Documents\Dads Music\", ftp, 27)
             
End Sub

Function FileInfo(path, filename, item) As Variant
' this gets the file duration
    Dim objShell As IShellDispatch4
    Dim objFolder As Folder3
    Dim objFolderItem As FolderItem2
      
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(path)
    Set objFolderItem = objFolder.ParseName(filename)
    
    FileInfo = objFolder.GetDetailsOf(objFolderItem, 27)
    b = FileInfo ' song run time. used to pause macro while song plays
           
    Set objShell = Nothing
    Set objFolder = Nothing
    Set objFolderItem = Nothing
End Function

Sub pause(seconds As Single)
  Dim TimeEnd As Long
           
           TimeEnd = Timer + seconds
        
            If TimeEnd > 86390 Then
                TimeEnd = 0
            End If
                
            Do
                DoEvents
            Loop Until TimeEnd <= Timer
        
        End Sub
smiler44
smiler44 is offline   Reply With Quote
Old 05-23-2019, 10:49 AM   #37
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 3,673
Thanks: 398
Thanked 637 Times in 618 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: get details of song being played

Quote:
Originally Posted by June7 View Post
I am not interested in building workbook.

Already have the file name in sub randomlyselectsong. As I stated, put code there to pull duration.
No need June7, he has the duration already stored in b as well in randomlyselectsong. So in fact he has everything he was asking for, just did not realise it.

__________________
Access novice. Sometimes trying to give something back.
Access 2007


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is online now   Reply With Quote
Old 05-23-2019, 10:53 AM   #38
smiler44
Newly Registered User
 
Join Date: Jul 2008
Location: UK
Posts: 637
Thanks: 13
Thanked 9 Times in 8 Posts
smiler44 is on a distinguished road
Re: get details of song being played

Quote:
Originally Posted by Gasman View Post
June7,
I've tweaked my copy a little to try and understand how it worked.

The call to RecursiveDir I changed to use f as that is the folder for the files in RandomlySelect sub?

That sub then uses that, plus ftp (the filename) and the item number.

It is very haphazard, and smiler44 has explained why.

To be fair to get it working as it is now would have been a monumental task for smiler44, so fair play.
Thank you Gasman, I was chuffed when it worked.

would i be taking the mickey if I asked what should it be

smiler44
smiler44 is offline   Reply With Quote
Old 05-23-2019, 11:03 AM   #39
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 3,673
Thanks: 398
Thanked 637 Times in 618 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: get details of song being played

What, what should be.?

I would walk through the code line by line with F8 and look and see what it does. Inspect the variables by either hovering over them or ? variablename in the Immediate window.

You can set breakpoints in the left column (red dot) and the code will stop there.

Do yourself a favour and get a book on Access. It will save you a load of time and effort.

Not being rude, so ignore the titles. There is even a pdf to start with.?

https://www.google.com/search?q=dumm...hrome&ie=UTF-8
__________________
Access novice. Sometimes trying to give something back.
Access 2007


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is online now   Reply With Quote
Old 05-23-2019, 11:04 AM   #40
smiler44
Newly Registered User
 
Join Date: Jul 2008
Location: UK
Posts: 637
Thanks: 13
Thanked 9 Times in 8 Posts
smiler44 is on a distinguished road
Re: get details of song being played

Quote:
Originally Posted by Gasman View Post
No need June7, he has the duration already stored in b as well in randomlyselectsong. So in fact he has everything he was asking for, just did not realise it.

Gasman, I think you may be misunderstanding or I am misunderstanding.
The code I have posted randomly selects a song from a directory and plays it.
If the duration of that song does not exceed the time to play songs for, it randomly plays another song and so it goes on.


In the macro i want, I have already manually opened the directory where the songs are stored, manually selected the songs I want and manually started playing them.

I now want to play songs for x time. The songs I have selected may take longer and so i need this new macro to now get the time of each song as it is played and when the total play time of each song played exceeds x time I want the macro to close windows media player. This I can do but I cannot start a macro to get the time of the song currently being played

ignoring any code i have posted, how do i get the duration of the song being played?


smiler44
smiler44 is offline   Reply With Quote
Old 05-23-2019, 11:13 AM   #41
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 3,673
Thanks: 398
Thanked 637 Times in 618 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: get details of song being played

OK, let me tell you what I think your code is doing.
You are already getting the duration, as you pause the code for that period, before selecting and playing another file.?

You have not told me how you file structure is setup, despite my asking a good few posts back.?

To me it looks like all the files are in one folder.?
It also looks like you have no other types of files in there BUT audio files.?
The code is not indented, so that makes it harder to read.

Am I correct in these statements?

If you need help with this other project, post the code for that project, better still upload the file, as I had to create textboxes etc to work through the code you posted.
__________________
Access novice. Sometimes trying to give something back.
Access 2007


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is online now   Reply With Quote
Old 05-23-2019, 11:13 AM   #42
smiler44
Newly Registered User
 
Join Date: Jul 2008
Location: UK
Posts: 637
Thanks: 13
Thanked 9 Times in 8 Posts
smiler44 is on a distinguished road
Re: get details of song being played

Quote:
Originally Posted by Gasman View Post
What, what should be.?

I would walk through the code line by line with F8 and look and see what it does. Inspect the variables by either hovering over them or ? variablename in the Immediate window.

You can set breakpoints in the left column (red dot) and the code will stop there.

Do yourself a favour and get a book on Access. It will save you a load of time and effort.

Not being rude, so ignore the titles. There is even a pdf to start with.?

https://www.google.com/search?q=dumm...hrome&ie=UTF-8
I've tried Access, could not get on with it and that was when I may have needed it for a job I was applying for. Now I dont need it, there is no way I could learn it I'm not that clever

macafee2
smiler44 is offline   Reply With Quote
Old 05-23-2019, 11:42 AM   #43
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 3,673
Thanks: 398
Thanked 637 Times in 618 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: get details of song being played

OK, I posted for Access, but what it and Excel have in common is VBA, and that is what you are trying to code in.
Look for a book on Excel VBA then.

Post your new project and I will try and assist as to how I would approach it.
I will not write it for you, but point you in what I think is the right direction.

Others will then be able to help as well.

Alternatively try and understand your first project especially the FileInfo sub and take it from there. You will find as you do these projects that some functions will become common to all.
__________________
Access novice. Sometimes trying to give something back.
Access 2007


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is online now   Reply With Quote
Old 05-23-2019, 11:47 AM   #44
smiler44
Newly Registered User
 
Join Date: Jul 2008
Location: UK
Posts: 637
Thanks: 13
Thanked 9 Times in 8 Posts
smiler44 is on a distinguished road
Re: get details of song being played

Quote:
Originally Posted by Gasman View Post
OK, let me tell you what I think your code is doing.
You are already getting the duration, as you pause the code for that period, before selecting and playing another file.?

You have not told me how you file structure is setup, despite my asking a good few posts back.?

To me it looks like all the files are in one folder.?
It also looks like you have no other types of files in there BUT audio files.?
The code is not indented, so that makes it harder to read.

Am I correct in these statements?

If you need help with this other project, post the code for that project, better still upload the file, as I had to create textboxes etc to work through the code you posted.

sorry I mised that.
The songs are in a directory in My Documents and has artists name followed by song title and file extension then date file created and duration . Adele - All out of love.mp3 12/11/16 13.42 00.03:50

yes you are correct all songs in one directory and no other files in that directory.
I apologize for not answering before, i really did miss that.

I have no code for the other project as I do not know how to get the title of the song that is being played or the duration of the song being played

smiler44
smiler44 is offline   Reply With Quote
Old 05-23-2019, 12:02 PM   #45
NauticalGent
Pristine Curmudgeon
Gold Supporter
 
NauticalGent's Avatar
 
Join Date: Apr 2015
Location: Naples, Italy (EXPAT from Virginia)
Posts: 1,780
Thanks: 386
Thanked 240 Times in 210 Posts
NauticalGent has a spectacular aura about NauticalGent has a spectacular aura about
Talking Re: get details of song being played

Quote:
Originally Posted by Gasman View Post
Hmm, what am I doing wrong

20 ABBA
21 Dancing Queen
Perhaps it is the song itself?

__________________
“I had the RIGHT to remain silent...but I didn’t have the ABILITY.” - Ron White
NauticalGent is online now   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Song Lyrics NauticalGent The Watercooler 36 10-18-2018 12:10 PM
Song and Band names KenHigg Politics & Current Events 2 12-05-2014 08:51 PM
Add a song to iTunes speakers_86 General 7 02-23-2012 09:03 PM
Well its been a while since I played with Queries so some noob help please. jam Queries 5 06-01-2009 06:23 AM
hymnal and song subform mikevds Forms 2 03-18-2009 09:08 AM




All times are GMT -8. The time now is 01:11 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World