Sign in to follow this  
Followers 0
svennie

Media UDF

48 posts in this topic

#1 ·  Posted (edited)

New version avaible: Version 1.3

Whats changed?

Bug fix: Fixed problems with _MediaSave function (thanks to Emperor!)

New version avaible: Version 1.2

Whats changed?

Bug fix: You can now play files with spaces in ther pathname.

New version avaible: Version 1.1

Whats changed?

New _MediaCut function

New _MediaCopy function

New _MediaPaste function

New _MediaDelete function

New _MediaCapture function

--------

Hello,

This UDF makes it possible to do a lot of things with Media files, like:

- Play sounds

- Play movies in Fullscreen, reversed, set the speed etc.

- Record sounds from a microphone

- Save files

- Cut, copy, paste, delete etc in media files.

And much more.

Here are the functions:

;===============================================================================
;
; Function Name:    _MediaOpen()
; Description:    Opens a media file.
; Parameter(s):  $s_location     - Location of the media file
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns Media ID needed for the other media functions
;                  On Failure - Returns 0  and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaCreate()
; Description:    Creates a new media for recording, capturing etc.
; Parameter(s):  $s_format   - Format of the file.
;                  0 = CD Audio
;                  1 = Digital video
;                  2 = Overlay
;                  3 = sequencer
;                  4 = Vcr
;                  5 = Video disc
;                  6 = Wave Audio
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns Media ID needed for the other media functions
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaPlay()
; Description:    Plays a opened media file.
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
;                  [optional] $i_From       - Sets time in seconds where to begin playing
;                  [optional] $i_To       - Sets time in seconds where to bstop playing
;                  [optional] $i_Speed     - Sets the speed to play with
;                  [optional] $f_Fast       - When 1 it will play faster then normal
;                  [optional] $f_Slow       - When 1 it will play slower then normal
;                  [optional] $f_Fullscreen  - When 1 movies will play fullscreen
;                  [optional] $f_Repeat   - When 1 it will keep repeating
;                  [optional] $f_Reverse     - When 1 the movie will been played reversed
;                  [optional] $f_Scan       - When 1 plays as fast as possible
;                  The default value of all the optional parameters is 0.
;                  Some file formats dont understand some of the optional functions
;                  Experimate with it.
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaRecord()
; Description:    Records from a microphone
;                  Stop recording with _MediaStop()
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaCut()
; Description:    Cuts a specified part of the movie to the clipboard.
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
;                  $i_From      - From time in seconds
;                  $i_To          - To time in seconds
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaCopy()
; Description:    Copies a specified part of the movie to the clipboard.
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
;                  $i_From      - From time in seconds
;                  $i_To          - To time in seconds
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaPaste()
; Description:    Paste media from the clipboard.
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaDelete()
; Description:    Deletes a specified part of the movie.
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
;                  $i_From      - From time in seconds
;                  $i_To          - To time in seconds
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaCapture()
; Description:    Copies the contents of the frame buffer and stores it in the
;                  specified file.
;                  Stop recording with _MediaStop()
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
;                  $s_Location  - Location where to store the file.
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaStop()
; Description:    Stops playing/recording of a Media ID
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaSeek()
; Description:    Moves to a specified Position and stops.
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
;                  $i_Position  - Position in seconds to move to, -1 goes to start
;                  -2 goes to end
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaPause()
; Description:    Pauses playing/recording of a Media ID
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaResume()
; Description:    Resumes playing/recording of a Media ID
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaSave()
; Description:    Saves a opened Media ID to the selected file
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
;                  $s_Location  - Location to save to (must be full path)
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================
;===============================================================================
;
; Function Name:    _MediaClose()
; Description:    Closes a existing Media ID
; Parameter(s):  $i_MediaId  - Media ID returned by _MediaOpen()/MediaCreate()
; Requirement(s):   AutoIt
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @ERROR = 1
; Author(s):        svennie
;
;===============================================================================

The examples included doesnt view all the functions, only the following:

_MediaOpen

_MediaPlay

_MediaStop

_MediaClose

_MediaCreate

_MediaRecord

_MediaSave

If you create a example please post it ;) .

Be sure you always use _MediaClose at te end of your script, or in the OnAutoItExit function.

When you not close the media file, the next time you run the application it will not work.

Since it is trying to open it in the first handle and it is still filled from the time we runned the program before :P .

Put the Media.au3 in your Include directory and enjoy!

Please tell me what you think about it and give me some feedback :mad2: .

Number of downloads v1.2: 769

Media_Example_PlayFile.au3

Media_Example_RecordSound.au3

Media.au3

Edited by svennie

Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites



Haven't been able to test them, but if they work...you my friend should be given an award. The recording functions are excactly what I have been looking for. I love you.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Can it play URLs? Can't test it now but try playing .pls(playlist) or this URL.

URL: http://205.188.234.2:8040

pls: attached, :P not permitted, download the txt then change the extention.

It runs in winamp! ;)

To read the pls in notepad you may have to change the LF returns to something else.

Edit: http://64.236.34.4/stream/1074 is the redirect of the other URL

shoutcast_playlist.txt

Edited by gamerman2360

Share this post


Link to post
Share on other sites

Can it play URLs? Can't test it now but try playing .pls(playlist) or this URL.

URL: http://205.188.234.2:8040

pls: attached, :mad2: not permitted, download the txt then change the extention.

It runs in winamp! :P

To read the pls in notepad you may have to change the LF returns to something else.

Edit: http://64.236.34.4/stream/1074 is the redirect of the other URL

I cannot test it at the moment, it says the server is full ;)

Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

Released version 1.1 of the UDF, see first post ;) .


Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

Wow. This is great. I just wish I could get it to work. Tried version 1.1 Media_Example_PlayFile.au3 with AVI and WAV files but it would not play any of them. Seems to exit after selecting file.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Wow. This is great. I just wish I could get it to work. Tried version 1.1 Media_Example_PlayFile.au3 with AVI and WAV files but it would not play any of them. Seems to exit after selecting file.

Very weird, on my pc it just works.

;)

Have you placed Media.au3 in your include directory (default C:/Program Files/AutoIt/Include)

EDIT: Found a bug, when you load a file with spaces in the pathname it will not work. This will been fixed in 1.2

EDIT: Released version 1.2, see first post

Edited by svennie

Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

I am trying to download some files but it seems that there are some problems.. Please check the links to see if the files exist..

Media.au3 ( 10.08k ) <== Cannot Download

Media_Example_PlayFile.au3 <== Download Ok

Media_Example_RecordSound.au3 <== Cannot Download

I would like to try it but the links have a problem.. Thanks..

Cheers.. ;)

Share this post


Link to post
Share on other sites

YEH! I had Media.au3 in same folder as Media_Example_PlayFile.au3 thinking it would be found there. When I moved it to the Include folder in the program file folder it works (sort of). Videos play but video window does not close at end of file. Thanks for your help and for generating these. Does program close video window at end of file for you?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

YEH! I had Media.au3 in same folder as Media_Example_PlayFile.au3 thinking it would be found there. When I moved it to the Include folder in the program file folder it works (sort of). Videos play but video window does not close at end of file. Thanks for your help and for generating these. Does program close video window at end of file for you?

Yes, if you not set the repeat parameter ;) . Edited by svennie

Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I am trying to download some files but it seems that there are some problems.. Please check the links to see if the files exist..

Media.au3 ( 10.08k ) <== Cannot Download

Media_Example_PlayFile.au3 <== Download Ok

Media_Example_RecordSound.au3 <== Cannot Download

I would like to try it but the links have a problem.. Thanks..

Cheers.. :P

They just work for me ;) .

What you see when you try to download them?

EDIT: Putted them on my fileman, see first post.

Edited by svennie

Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

They just work for me ;) .

What you see when you try to download them?

EDIT: Putted them on my fileman, see first post.

@Svennie, works now thanks. Not sure what the deal was before.. Now I can play.. Thanks!

Cheers.. :P

Share this post


Link to post
Share on other sites
;) It works!! Thank you sir!

Share this post


Link to post
Share on other sites

How can i do this: One .mp3 plays and when its over an other starts to playing. How can i read, when music is over?

Share this post


Link to post
Share on other sites

Nice work man, just what i was looking for B)

Share this post


Link to post
Share on other sites

I was wondering if it might be possible to create a command that records from another input rather than just the microphone....say for example the audio output of your computer?.....would it record as an mp3 or possibly convert a wav into an mp3 later on?

Thanks.

Share this post


Link to post
Share on other sites

Option Explicit
'Requires a reference to:
' Microsoft Shell Controls and Automation (shell32.dll)

'Uses techniques found here:
'http://www.microsoft.com/resources/documentation/windows/2000/server/scriptguide/en-us/sas_fil_lunl.mspx

Public objShell As IShellDispatch4

Public Type BROWSEINFO
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type

'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
  Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) _
  As Long

Declare Function SHBrowseForFolder Lib "shell32.dll" _
  Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long


Sub DisplayMP3Info()
    Dim i As Long
    Dim Folder As String
    Dim StrLen As Long, FolderLen As Long
    Dim NameOnly As String
    Dim Row As Long
    
'   Prompt for the directory
    Folder = GetDirectory("Select a directory that has MP3 files")
    Set objShell = CreateObject("Shell.Application")
    
    FolderLen = Len(Folder)
    With Application.FileSearch
        .NewSearch
        .LookIn = Folder
        .SearchSubFolders = True
        .FileType = msoFileTypeAllFiles
        If .Execute > 1 Then
            If .FoundFiles.Count = 0 Then
                MsgBox "Error - No files.", vbCritical
                GoTo ExitSub
                Exit Sub
            End If
            Row = 1
            Worksheets("Sheet1").Activate
            ActiveSheet.Cells.Clear
            With ActiveSheet.Range("A1:K1")
                .Value = Array("Path", "Filename", "Size", "Date/Time", "Artist", "Album Title", "Year", "Track No.", "Genre", "Duration", "Bit Rate")
                .Font.Bold = True
            End With
            Application.ScreenUpdating = False
            For i = 1 To .FoundFiles.Count
                If i Mod (100) = 0 Then
                    DoEvents
                    Application.StatusBar = "Working on " & i & " of " & .FoundFiles.Count
                End If
                If Right(.FoundFiles(i), 3) = "mp3" Then
                    Row = Row + 1
                    'Parse the directory path to get genre, artist, and album name, and song title
                    ActiveSheet.Cells(Row, 1) = .FoundFiles(i)
                    ActiveSheet.Cells(Row, 2) = FileNameOnly(.FoundFiles(i))
                    ActiveSheet.Cells(Row, 3) = FileLen(.FoundFiles(i)) ' file size
                    ActiveSheet.Cells(Row, 4) = FileDateTime(.FoundFiles(i))  'date
                    ActiveSheet.Cells(Row, 5) = GetMP3TagInfo(.FoundFiles(i), 16) 'artist
                    ActiveSheet.Cells(Row, 6) = GetMP3TagInfo(.FoundFiles(i), 17) 'album title
                    ActiveSheet.Cells(Row, 7) = GetMP3TagInfo(.FoundFiles(i), 18) 'year
                    ActiveSheet.Cells(Row, 8) = GetMP3TagInfo(.FoundFiles(i), 19) 'track number
                    ActiveSheet.Cells(Row, 9) = GetMP3TagInfo(.FoundFiles(i), 20) 'duration
                    ActiveSheet.Cells(Row, 10) = GetMP3TagInfo(.FoundFiles(i), 21) 'genre
                    ActiveSheet.Cells(Row, 11) = GetMP3TagInfo(.FoundFiles(i), 22) 'bit rate
                End If
            Next i
        End If
    End With
ExitSub:
    'update the pivot table
    ActiveSheet.UsedRange.Name = "Data"
    Worksheets("pivot").PivotTables("PivotTable1").PivotCache.Refresh
    
    Set objShell = Nothing
    Application.StatusBar = False
End Sub
   
Function GetMP3TagInfo(FolderName, ItemNum)
    Dim strFilename
    Dim objFolder As Folder3
    Dim objFolderItem As FolderItem2
    Dim FileName As String
    
    FileName = FileNameOnly(FolderName)
    Set objFolder = objShell.Namespace(Left(FolderName, Len(FolderName) - Len(FileName)))
    Set objFolderItem = objFolder.ParseName(FileName)
    GetMP3TagInfo = objFolder.GetDetailsOf(objFolderItem, ItemNum)
End Function


Function FileNameOnly(FullPath) As String
    Dim i As Long
    Dim FN As String
    If Right(FullPath, 1) = "\" Then FullPath = Left(FullPath, Len(FullPath) - 1)
    For i = Len(FullPath) To 1 Step -1
        If Mid(FullPath, i, 1) = "\" Then
            FileNameOnly = FN
            Exit Function
        Else
            FN = Mid(FullPath, i, 1) & FN
        End If
    Next i
End Function


Function GetDirectory(Optional Msg) As String
    Dim bInfo As BROWSEINFO
    Dim path As String
    Dim r As Long, x As Long, pos As Integer
 
'   Root folder = Desktop
    bInfo.pidlRoot = 0&

'   Title in the dialog
    If IsMissing(Msg) Then
        bInfo.lpszTitle = "Select a folder."
    Else
        bInfo.lpszTitle = Msg
    End If
    
'   Type of directory to return
    bInfo.ulFlags = &H1

'   Display the dialog
    x = SHBrowseForFolder(bInfo)
    
'   Parse the result
    path = Space$(512)
    r = SHGetPathFromIDList(ByVal x, ByVal path)
    If r Then
        pos = InStr(path, Chr$(0))
        GetDirectory = Left(path, pos - 1)
    Else
        GetDirectory = ""
    End If
End Function

can someone extract the function in this code .. it might help in getting info off mp3s


i think

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Because everyone want to save as MP3 i will add a convert function (or let you immediatly save as mp3) to the next version B) .

Edited by svennie

Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

Is there any way to convert .wma to .mp3? I tried FileCopy() B) , but its not working.

Share this post


Link to post
Share on other sites

Is there any way to convert .wma to .mp3? I tried FileCopy() B) , but its not working.

Do you mean WAV instead of WMA?

If so:

Because everyone want to save as MP3 i will add a convert function (or let you immediatly save as mp3) to the next version :o .

And if you really mean WMA please say :">

Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0