Sign in to follow this  
Followers 0
lorenkinzel

FileReadLine difficulty

7 posts in this topic

I've been working on a minimal media player & all is well except for playing the list from .ini. I can only get it to read the last line from the .ini.Everything (by appearances) is O.K. except for lines 74-79.

Any pointers would be greatly appreciated.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=play.ico
#AutoIt3Wrapper_Res_Comment=Small media player
#AutoIt3Wrapper_Res_Description=Small media player
#AutoIt3Wrapper_Res_Fileversion=1.1.1.1
#AutoIt3Wrapper_Res_LegalCopyright=Lorens' S--T
#AutoIt3Wrapper_Res_Language=1032
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Sound.au3>
#include <SliderConstants.au3>
#include <file.au3>
#include <Misc.Au3>
#include <String.Au3>
#include <GUIListBox.Au3>



Dim $Read, $List1, $File

$Form1 = GUICreate("SoundPlay      mpCubed, dotWav, dotAvi, dotWma,   etc>(all files)", 574, 115, 10, 10)
GUISetBkColor(0x3D95FF)
WinSetTrans("SoundPlay      mpCubed, dotWav, dotAvi, dotWma,   etc>(all files)", "", 190)

$Label1 = GUICtrlCreateLabel("", 8, 8, 450, 45)

$LoadButton = GUICtrlCreateButton("Load", 468, 8, 41, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
$playButton = GUICtrlCreateButton("Play", 468, 34, 41, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
$pauseButton = GUICtrlCreateButton("Pause", 468, 60, 41, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
$stopButton = GUICtrlCreateButton("Stop", 468, 86, 41, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
$playlistButton = GUICtrlCreateButton("Playlist", 513, 8, 54, 25); show the playlist
GUICtrlSetBkColor(-1, 0xFF0000)
$playAllButton = GUICtrlCreateButton("Play > List", 513, 34, 54, 25); play the whole list; ideally
GUICtrlSetBkColor(-1, 0xFF0000)

$Slider1 = GUICtrlCreateSlider(8, 86, 450, 25, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS))
GUICtrlSetBkColor(-1, 0x3D95FF)
GUICtrlSetData(-1, 100)



GUISetState()



While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit

        Case $nMsg = $LoadButton
            $Opened_File = FileOpenDialog("Open Music File", "", "All Music Files (*.wav;*.avi;*.mp3;*.wma)|All Files (*.*)", 12)
            GUICtrlSetData($Label1, $Opened_File)


        Case $nMsg = $playButton
            $Read = GUICtrlRead($Label1)
            _SoundPlay($Read)


        Case $nMsg = $playlistButton
            Run(@ScriptDir & "\Playlist.exe")

            ;Problem area--it only plays the song on the last line of the .ini
        Case $nMsg = $playAllButton
            $File = (@ScriptDir & "\Playlist.ini")
            For $A = 1 To _FileCountLines($File)
                $List1 = FileReadLine($File, $A)
            Next
            _SoundPlay($List1)



        Case $nMsg = $pauseButton
            _SoundPause($Read)
            _SoundPause($List1)


        Case $nMsg = $stopButton
            _SoundStop($Read)
            _SoundStop($List1)

Share this post


Link to post
Share on other sites



First off, why are you using FileReadLine() which is very slow at the best of times, when you could be using IniReadSection() and IniRead()? That is assuming you indeed have a properly formatted ini file.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Lack of experience / know-how.

The ini was written with FileWriteLine & has no sections, etc. if that is what you mean by formatting.

I suppose I could give IniReadSection() and IniRead() a try....

Share this post


Link to post
Share on other sites

Create the file with the proper format and you will save yourself a lot of trouble. If you can't do that and you still have to use a text file (saving plain text as an ini file doesn't make it an ini file) post your file at least up to a few lines after it stops and we'll see what is happening and find you a better solution than FileReadLine().

That function starts at the beginning, reads down to the line you want then goes back to the beginning to start the cycle over again for the next line so it can't possibly be fast.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Besides constantly opening and closing the file to read line by line as suggested by GeoSoft, I'll address an issue that popped out at me just peeking at your code and will not iterate past that.

Using quote tags so I can highlight:

$File = (@ScriptDir & "\Playlist.ini")

For $A = 1 To _FileCountLines($File)

$List1 = FileReadLine($File, $A)

Next

_SoundPlay($List1)

I have no idea what _SoundPlay() requires as it's first parameter value. But saying $List1 = will only ever allow $List1 to contain the last value fed to it.

Edit:

Didn't know it was an AutoIt included UDF :) . It only accepts one file.

You're looping through all the files I assume, but you're still only giving it the last line every time.

So I'm not entirely sure why you're looping unless you want to do something like:

Global $ga_lines = StringSplit(StringStripCR(FileRead($File)), @LF)
    For $iline = 1 To $ga_lines[0]
        _SoundPlay($ga_lines[$iline], 1); Using one so that it waits until sound is finished
    Next
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Yeah, I'll add my two penneth here...

The INI read functions in AutoIT are fantastic and once you get your head round them make life so much easier. If you're reading from an INI file then that's the best way to go.

On from that, when you are typically only seeing execution from the LAST line of a list then it suggests that your intelligence isn't quite up to the process of hitting each individual line. For example (basic basic basic simple concept):

1. This is

2. a collection

3. of text

4. in different

5. lines.

6. The End

For $i = 1 to 6
    $LotsOfText = $Text[$i] ; Let's say we put it into an array
Next
MsgBox(0,"Text", $LotsOfText)

That's gonna just return "The End" as the code hasn't properly taken into account the other lines in the list. This is similar to how your code is set up... You have told it to read through each line of the list but you've only told it to play the file AFTER it's looped through to the very end.

Case $nMsg = $playAllButton
            $File = (@ScriptDir & "\Playlist.ini")
            For $A = 1 To _FileCountLines($File)
                $List1 = FileReadLine($File, $A)
                _SoundPlay($List1) ; Moving the SoundPlay inside the loop means it will be executed in turn
            Next

Mal

(Yes, I know it's essentially a repeat... Hopefully it explains it better for a newbie)

Edited by Mallie99

Are you telling me something I need to know or something I want to know?

Share this post


Link to post
Share on other sites

Mallie99

Yes, that really does explain it better for a newbie. Hence the familliar saying "out of the loop"; only seeing net results rather than inner workings.

Thanks everyone. The learning process can be frustrating, but well worthwhile. I can make this work now, give a quick hurray, & move on to IniReadSection ().

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