Go Back   Access World Forums > Apps and Windows > Excel

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-22-2019, 11:32 AM   #1
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
get details of song being played

This is the situation.
I have selected some songs to play via windows media player, they start playing.


I want the songs to play for x number of minutes. so I start excel tell it how long to play for and run the macro.


I cannot work out how to :-
1. get the duration of the song being played
2. get the title of the song being played

if you could help with either I'd be grateful. 1 is my first choice to be solved
but from 2 could possibly solve 1



I could solve this with a timer counting down to zero but would prefer to solve it but solving 1.

thank you

smiler44

smiler44 is offline   Reply With Quote
Old 05-22-2019, 11:58 AM   #2
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,365
Thanks: 555
Thanked 948 Times in 897 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: get details of song being played

Is this any good?

https://youtu.be/g1RN8DBuSlI
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Old 05-22-2019, 12:21 PM   #3
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,527
Thanks: 441
Thanked 841 Times in 812 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: get details of song being played

Have a look here re the links offered by Daniel Pineault.

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

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 05-22-2019, 12:49 PM   #4
June7
AWF VIP
 
June7's Avatar
 
Join Date: Mar 2014
Location: The Great Land
Posts: 2,464
Thanks: 0
Thanked 573 Times in 569 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: get details of song being played

Only place I can find duration is Windows file properties. Example:

Code:
Sub GetLength()
With CreateObject("shell.application").Namespace("C:\Users\June\")
    Debug.Print Mid(Join(Filter(Split(.GetDetailsOf(.Items.Item("Test.mp3"), -1), vbLf), "Length: "), ""), 9)
End With
End Sub
How are you selecting files to play? Are you using ActiveX Windows Media Player control embedded in worksheet? I have tested WMP control embedded in Access form.
__________________
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.

Last edited by June7; 05-22-2019 at 01:06 PM.
June7 is offline   Reply With Quote
The Following User Says Thank You to June7 For This Useful Post:
Gasman (05-22-2019)
Old 05-22-2019, 01:06 PM   #5
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,527
Thanks: 441
Thanked 841 Times in 812 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: get details of song being played

June7,
I've just tried it on one of my mp3 files that does have the duration in it and I get nothing.?
Code:
Sub GetLength()
Dim oFolder As Object
'Set oFolder = CreateObject("shell.application").Namespace("M:\ABBA\Gold Greatest Hits\")
With CreateObject("shell.application").Namespace("M:\ABBA\Gold Greatest Hits\")
    Debug.Print Mid(Join(Filter(Split(.GetDetailsOf(.Items.Item("01 - Dancing Queen.mp3"), -1), vbLf), "Length: "), ""), 9)
End With
End Sub
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 05-22-2019, 01:26 PM   #6
June7
AWF VIP
 
June7's Avatar
 
Join Date: Mar 2014
Location: The Great Land
Posts: 2,464
Thanks: 0
Thanked 573 Times in 569 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: get details of song being played

I tested with an mp4 and it did work so I assumed mp3 would. So just tested with mp3 and it also works for me.
__________________
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 offline   Reply With Quote
Old 05-22-2019, 01:40 PM   #7
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,289
Thanks: 115
Thanked 3,090 Times in 2,808 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: get details of song being played

All details about artist, title, duration, bit rate etc for audio files are all available as extended properties of the file and can be obtained using the GetDetailsOf method.
Some time ago I created an example database containing all you need to do this. It can be used to get the extended properties for any type of file.
You can find this app both here https://www.access-programmers.co.uk...d.php?t=294548 and on my website http://www.mendipdatasystems.co.uk/e...ies/4594398115

Hope that is of use to you

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Colin (Mendip Data Systems)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Common sense and a sense of humour are the same thing, moving at different speeds. (Clive James - RIP)
isladogs is offline   Reply With Quote
Old 05-22-2019, 01:50 PM   #8
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,527
Thanks: 441
Thanked 841 Times in 812 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: get details of song being played

Hmm, what am I doing wrong

I did discover that it is in item 27 though?
Code:
Sub GetLength()
Dim oFolder As Object
Dim varItem As Variant
Dim i As Integer

'Set oFolder = CreateObject("shell.application").Namespace("D:\Music\ABBA\Gold Greatest Hits\")
With CreateObject("shell.application").Namespace("M:\ABBA\Gold Greatest Hits\")
    For i = -1 To 30
        Debug.Print i & " " & .GetDetailsOf(.Items.Item("01 - Dancing Queen.mp3"), i) ', vbLf), "Length: "), "")
    'Debug.Print Mid(Join(Filter(Split(.GetDetailsOf(.Items.Item("01 - Dancing Queen.mp3"), -1), vbLf), "Length: "), ""), 9)
    Next
End With
End Sub
-1 Type: MP3 Audio File (VLC)
Size: 3.55 MB
Date modified: ?18/?08/?2009 ??14:27
0 01 - Dancing Queen.mp3
1 3.55 MB
2 MP3 Audio File (VLC)
3 18/08/2009 14:27
4 18/08/2009 14:27
5 22/05/2019 22:53
6 N
7 Online
8 Online only
9 Audio
10 Unix User\nobody
11 Music
12
13 ABBA
14 Gold: Greatest Hits
15 1993
16 Rock/Pop
17
18
19 Unrated
20 ABBA
21 Dancing Queen
22
23
24
25
26 1
27 00:03:52
28 ?128kbps
29 No
30
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 05-22-2019, 02:00 PM   #9
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,289
Thanks: 115
Thanked 3,090 Times in 2,808 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: get details of song being played

There are a total of 310 or so extended properties so stopping at number 30 means you may be missing several properties related to MP3 files
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Colin (Mendip Data Systems)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Common sense and a sense of humour are the same thing, moving at different speeds. (Clive James - RIP)
isladogs is offline   Reply With Quote
Old 05-22-2019, 10:47 PM   #10
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,527
Thanks: 441
Thanked 841 Times in 812 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: get details of song being played

Quote:
Originally Posted by June7 View Post
I tested with an mp4 and it did work so I assumed mp3 would. So just tested with mp3 and it also works for me.
June7
Would I need a particular reference? I am puzzled as I just copied your code and changed the filename, so keen to find out why it does not work.
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 05-22-2019, 11:13 PM   #11
June7
AWF VIP
 
June7's Avatar
 
Join Date: Mar 2014
Location: The Great Land
Posts: 2,464
Thanks: 0
Thanked 573 Times in 569 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: get details of song being played

I did not add any library. Just tested in a brand new db and works.
__________________
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 offline   Reply With Quote
Old 05-22-2019, 11:13 PM   #12
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,527
Thanks: 441
Thanked 841 Times in 812 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: get details of song being played

Quote:
Originally Posted by isladogs View Post
There are a total of 310 or so extended properties so stopping at number 30 means you may be missing several properties related to MP3 files
Thanks Colin,
That was just to see where my code was not working. I started at 20 and did not see the duration and so upped it to 30, where I did.
Good to know there the limit though.
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 05-22-2019, 11:13 PM   #13
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
Only place I can find duration is Windows file properties. Example:

Code:
Sub GetLength()
With CreateObject("shell.application").Namespace("C:\Users\June\")
    Debug.Print Mid(Join(Filter(Split(.GetDetailsOf(.Items.Item("Test.mp3"), -1), vbLf), "Length: "), ""), 9)
End With
End Sub
How are you selecting files to play? Are you using ActiveX Windows Media Player control embedded in worksheet? I have tested WMP control embedded in Access form.
i am selecting songs to play using windows explorer, opening the directory, selecting the songs and pressing play.

am i right in thinking your code requires me to know the title of the song?
This is something i will need to obtain via code, i cannot pre program it

i am not using Access just using excel, i'm no good with Access

smiler44
smiler44 is offline   Reply With Quote
Old 05-22-2019, 11:19 PM   #14
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 Uncle Gizmo View Post
I dont think so. I did find code doing an internet search that did the same or similar. This code lists the attributes and unless i can work out what song is being played, i cannot go the the attributes and retrieve the duration.

smiler44
smiler44 is offline   Reply With Quote
Old 05-22-2019, 11:35 PM   #15
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

i created a marco with help from here and the internet that randomly plays songs for a pre determined time.

i hope this is all of it. it may look as if i declare part way through a module but in fact this code is over 2 or more modules and the declarations are at the top

Code:
Dim fd 'file duration of song

Dim filetoplay ' the mp3 file to play
Global spt As String


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





Sub durationplayed()



'how many minutes music has played for after selected song plays
Dim fdsec As Integer ' file durtion seconds 00:10
Dim fdm As Integer 'file duration minutes 10:00

Dim sec As Integer '  seconds 00:10
Dim m As Integer 'minutes 10:00
Dim mm

'fd can be found in fileduration sub
'fd = "3:33"

fdsec = Mid(fd, 3, 2) 'gets file duration seconds
fdm = Left(fd, 1) 'gets fie duration minutes

sec = Mid(Sheet1.TextBox2, 4, 2) 'gets seconds in text box 2
m = Left(Sheet1.TextBox2, 2) 'gets mintes in text box 2

mm = fdm + m & ":" & fdsec + sec

If fdsec + sec > 60 Then ' if seconds are more then 60
m = m + 1
mm = fdm + m & ":" & fdsec + sec - 60
End If

Sheet1.TextBox2.Value = mm

End Sub

Sub shutdown()

Shell ("taskkill /f /im wmplayer.exe") 'shutdown windows media player
Shell "shutdown -s -t 05", vbHide 'shut down laptop
Application.Quit
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:\path\directory where songs are kept")

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:\path\directory where songs are kept Music\" & ftp
Shell "C:\path\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:\path\directory where songs are kept\", 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
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 05:04 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