Jump to content

Picky file selection


Recommended Posts

Hello, I am making a simple media player. Everything works like it is supposed to except sometimes it won't open certain mp3 files and give an error that's not even there. If someone could be kind enough to help me figure this out I would be grateful. Thanks to anyone who helps.

#include <GUIConstantsEx.au3>
#include <Sound.au3>

GUICreate("Music Player", 300, 140)
GUISetState()

$B_Pause = 0
$B_Play = GUICtrlCreateButton("Play", 10, 90, 70, 25)
$B_Stop = GUICtrlCreateButton("Stop", 90, 90, 70, 25)
GUICtrlSetState($B_Play, $GUI_DISABLE)
GUICtrlSetState($B_Stop, $GUI_DISABLE)

$Menu = GUICtrlCreateMenu("File")
$M_Open = GUICtrlCreateMenuItem("Open", $Menu)
$M_Exit = GUICtrlCreateMenuItem("Exit", $Menu)

$S_SongPosCheck = ""
$S_Name = GUICtrlCreateLabel("", 10, 10, 280, 20)
$S_SongPos = GUICtrlCreateLabel("00:00:00 / 00:00:00", 10, 40, 200, 20)
$S_SongFile = ""

$C_Repeat = GUICtrlCreateCheckbox("Repeat", 200, 93)
GUICtrlSetState($C_Repeat, $GUI_DISABLE)

$Sl_Volume = GUICtrlCreateSlider(10, 60, 280, 20)
GUICtrlSetLimit($Sl_Volume, 100, 0)
GUICtrlSetData($Sl_Volume, 50)
$Sl_VolumeCheck = ""

While 1
    sleep(10)
    $M_MousePos = MouseGetPos()
    $S_FilePos = _SoundPos($S_SongFile)
    $C_RepeatCheck = GUICtrlRead($C_Repeat)
    $Sl_VolumeNum = GUICtrlRead($Sl_Volume)
    
    If $Sl_VolumeCheck <> $Sl_VolumeNum Then
        SoundSetWaveVolume($Sl_VolumeNum)
        TrayTip("", $Sl_VolumeNum, 5)
        $Sl_VolumeCheck = $Sl_VolumeNum
    ElseIf $Sl_VolumeCheck = $Sl_VolumeNum Then
        TrayTip("", "", 5)
    EndIf
    
    If $S_SongPosCheck <> $S_FilePos Then
        GUICtrlSetData($S_SongPos, _SoundPos($S_SongFile) & " / " & _SoundLength($S_Song))
        $S_SongPosCheck = $S_FilePos
    EndIf
    
    If $S_FilePos = _SoundLength($S_SongFile) Then
        _SoundStop($S_SongFile)
        If $C_RepeatCheck = $GUI_CHECKED Then
            _SoundStop($S_SongFile)
            _SoundPlay($S_SongFile)
        EndIf
    EndIf
    
    
    
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $M_Exit
        Exit
    Case $msg = $M_Open

        GUICtrlSetState($B_Stop, $GUI_DISABLE)
        GUICtrlSetState($C_Repeat, $GUI_DISABLE)
        GUICtrlSetData($B_Play, "Play")
        $B_Pause = 0
        $S_Song = FileOpenDialog("Select an audio file", "", "Sound File (*.wav;*.mp3)", 3)
        $S_SongNameSplit = StringSplit($S_Song, "\")
        $S_SongNameGetSplit = $S_SongNameSplit[0]
        
        If @error Then
            $S_SongNameSplit = ""
            GUICtrlSetData($S_SongPos, "00:00:00 / 00:00:00")
            _SoundStop($S_SongFile)
            _SoundClose($S_SongFile)
        EndIf
        
        If $S_SongNameSplit <> "" Then
            _SoundStop($S_SongFile)
            _SoundClose($S_SongFile)
            GUICtrlSetData($S_Name, $S_SongNameSplit[$S_SongNameGetSplit])
            GUICtrlSetState($B_Play, $GUI_ENABLE)
            $S_SongFile = _SoundOpen($S_Song)
            GUICtrlSetData($S_SongPos, _SoundPos($S_Song) & " / " & _SoundLength($S_Song))
        Else
            GUICtrlSetState($B_Play, $GUI_DISABLE)
            GUICtrlSetState($C_Repeat, $GUI_DISABLE)
            GUICtrlSetData($S_Name, "")
            GUICtrlSetData($S_SongPos, "00:00:00 / 00:00:00")
        EndIf
    Case $msg = $B_Play
        If $B_Pause = 0 Then
            GUICtrlSetData($B_Play, "Pause")
            GUICtrlSetState($B_Stop, $GUI_ENABLE)
            GUICtrlSetState($C_Repeat, $GUI_ENABLE)
            _SoundPlay($S_SongFile)
            $B_Pause = 1
        ElseIf $B_Pause = 1 Then
            GUICtrlSetData($B_Play, "Play")
            _SoundPause($S_SongFile)
            $B_Pause = 0
        EndIf
    Case $msg = $B_Stop
        GUICtrlSetState($B_Stop, $GUI_DISABLE)
        GUICtrlSetState($C_Repeat, $GUI_DISABLE)
        GUICtrlSetData($B_Play, "Play")
        $B_Pause = 0
        _SoundStop($S_SongFile)
    EndSelect
WEnd
Edited by Donald8282
Link to comment
Share on other sites

Hello,

I cannot reproduce the error. It works for me.

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

Donald8282,

As one of the authors of the Sound UDF, I take a keen interest in this. A number of people have had problems recently trying to open certain mp3 files with the UDF and there appears to be no common solution - if indeed any solution at all. :P

Personally I have only ever had trouble with (legally) downloaded files which have masses of proprietary information in the ID3 tag. In all of the cases I have come across in my collection, completely clearing the tags and then rewriting them has solved the problem. I used ID3Kill to get rid of the tags - it is freeware, very simple to use and you can get it here.

Try this on copies of your recalcitrant mp3 files and see if it does the trick for you as well. Please let us know the result. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba23, Thank you for sharing this.

The error is:

C:\Program Files\AutoIt3\Include\Sound.au3 (346) : ==> Subscript used with non-Array variable.:
__SoundMciSendString("set " & $aSndID[0] & " time format miliseconds")
__SoundMciSendString("set " & $aSndID^ ERROR

After running ID3KILL, the result is still the same.

Link to comment
Share on other sites

  • Moderators

Donald8282,

That happens because _SoundOpen does not return the expected array. Could you please run the following and see what MCI error you are getting returned in @extended (assuming it fails!)?

#Include <Sound.au3>

$aSndID = _SoundOpen("Your_MP3_Path")

If @error Then
    MsgBox(0, "Error", "Error: " & @error & @CRLF & "Extended: " & @extended)
Else
    MsgBox(0, "Success", $aSndID[1])
EndIf

Most other problem files have returned @extended = 10:

If the device has a "FailReasonString" value in its hardware key, that string is displayed as the error message. The driver or enumerator
places this registry string value there. If there is no "FailReasonString" in the hardware key, the following generic error message is
displayed:

This device is either not present, not working properly, or does not have all the drivers installed. (Code 10)

Try upgrading the device drivers for this device. 

Solution: Update Driver

To resolve this error code, make sure the device is connected to the computer correctly. For example, make sure all cables are plugged in
fully and that all adapter cards are properly seated. Follow the suggested solution button and update the device driver. It may be possible
to remove the device and redetect it using the Add New Hardware wizard.

Which, given that the device is usually connected and has up-to-date drivers, leaves us none the wiser as to why it happens. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Donald8282,

There are times when I wish I was not proved right! :P

I am afraid no-one here has been able to resolve this problem - if you do find a solution, please let us know. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Donald8282,

Well, at least you now know how to deal with the problem files - just check if there is an error on opening and skip them if there is. That way you will avoid the hard crash when you try to access the non-existent array. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Donald8282,

Sounds like it might have been a corrupt rip which defeated the MCI DLL (a standard Windows DLL which Sound uses to do its magic) but not Audacity - I really like that app! :x

Thank you for that good news - I shall pass it on to any future sufferers who post with similar symptoms. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...