Microsoft Small Basic
Program Listing:
Embed this in your website
<object id='sbapp' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='640' height='480'> <param name='source' value='http://smallbasic.com/program/ClientBin/SBWeb.xap'/> <param name='onError' value='onSilverlightError' /> <param name='background' value='white' /> <param name='minRuntimeVersion' value='3.0.40624.0' /> <param name='autoUpgrade' value='true' /> <param name='initParams' value='programId=QTD813' /> </object>
' This program is made by Amir originally .
' Background photo is absolu's. (Mp3 Player Slider Position update issue. partially cropped.)
' Tiles are copied from Excel.
DataExtension
.
Init
(
)
' this is not necessary
init
(
)
' init view
Control_button
(
)
' control button setting
Add_List
(
)
' write music(movie) dummy list in the ListBox
Open_Files
(
)
' gets music moview files
Player
=
Media
.
CreateMediaPlayer
(
Files_Array
[
Song_Id
]
,
178
,
92
,
405
,
266
)
' Open first file song_id=1
While
"True"
Media_Position
=
(
Media
.
GetPosition
(
Player
)
*
100
)
/
Media
.
GetLength
(
Player
)
' ##.# %
GameControls
.
SetValue
(
Seek_Bar
,
Media_Position
/
10
)
' #.## %
Min
=
Math
.
Floor
(
Media
.
GetPosition
(
Player
)
/
1000
/
60
)
' ## min
Secs
=
Math
.
Floor
(
Math
.
Remainder
(
Media
.
GetPosition
(
Player
)
/
1000
,
60
)
)
' ## sec
GameControls
.
SetText
(
Time_Box
,
Min
+
"m "
+
Secs
+
"s"
)
If
Media_Position
>=
99.9
then
' End point
Play_Next
(
)
EndIf
endwhile
Sub
Open_Files
MM
=
0
' initialize
Dir
=
Dialogs
.
AskForDirectory
(
)
' Select a music(movie) directory
GameWindow
.
Title
=
"Small Music Player - By Amir "
+
Dir
' title
reset_list
(
)
' reset list
RawFiles_Array
=
FilePlus
.
GetFiles
(
Dir
)
' gets visible files & RawFilesArray = Original Array
Total_Files
=
Array
.
GetItemCount
(
RawFiles_Array
)
' array number
For
i
=
1
To
Total_Files
CurrentExt
=
FilePlus
.
GetFileExtension
(
RawFiles_Array
[
i
]
)
' gets extension name
If
text
.
IsSubText
(
Musicext
,
CurrentExt
)
=
"True"
then
' compare if music( movie) file exists
MM
=
MM
+
1
Files_Array
[
MM
]
=
RawFiles_Array
[
i
]
EndIf
EndFor
Song_Id
=
1
' First file To Play
Scroll
(
)
' set music(movie) list
Stop_Song
(
)
SetVolume
(
)
' set volume
GameControls
.
SetText
(
Folder
,
Dir
)
EndSub
Sub
reset_list
If
Total_Files
=
0
Then
Total_Files
=
24
EndIf
For
i
=
1
To
Total_Files
Files_Array
[
i
]
=
" "
' reset
EndFor
EndSub
Sub
Play_Song
If
GameControls
.
GetText
(
Play_Button
)
=
"〓"
Then
' pause icon
Media
.
Pause
(
Player
)
GameControls
.
SetText
(
Play_Button
,
"▲"
)
' play icon
elseif
GameControls
.
GetText
(
Play_Button
)
=
"▲"
Then
Media
.
Resume
(
Player
)
GameControls
.
SetText
(
Play_Button
,
"〓"
)
elseif
GameControls
.
GetText
(
F_Open
)
=
"▲"
Then
' file open icon
Media
.
SetMedia
(
Player
,
Files_Array
[
1
]
)
' start file = 1
Media
.
Play
(
Player
)
EndIf
EndSub
Sub
Play_Next
Media
.
Stop
(
Player
)
Song_Id
=
Song_Id
+
1
If
Song_Id
>
Total_Files
Then
Song_Id
=
Total_Files
EndIf
Media
.
SetMedia
(
Player
,
Files_Array
[
Song_Id
]
)
' Song_ID is already +1
Scroll
(
)
GameControls
.
SetValue
(
Seek_Bar
,
0
)
' progress bar =0
Media
.
Play
(
Player
)
GameControls
.
SetText
(
Play_Button
,
"〓"
)
EndSub
Sub
Play_Prev
Media
.
stop
(
Player
)
Song_Id
=
Song_Id
-
1
If
Song_Id
<
1
Then
Song_Id
=
1
EndIf
Media
.
SetMedia
(
Player
,
Files_Array
[
Song_Id
]
)
' Song_ID is already -1
Scroll
(
)
GameControls
.
SetValue
(
Seek_Bar
,
0
)
' progress bar =0
GameControls
.
SetValue
(
Seek_Bar
,
0
)
Media
.
Play
(
Player
)
GameControls
.
SetText
(
Play_Button
,
"〓"
)
endSub
Sub
Stop_Song
Media
.
stop
(
Player
)
GameControls
.
SetText
(
Play_Button
,
"▲"
)
EndSub
Sub
Volume_Set
Vol_Value
=
GameControls
.
GetValue
(
Volume_Control_Bar
)
' gets current volume value
Media
.
SetVolume
(
Player
,
Vol_Value
/
100
)
' set
EndSub
Sub
Show
If
GameControls
.
GetText
(
Show_PlayList
)
=
"<<"
Then
' close
For
i
=
1200
To
613
Step
-
5
GameWindow
.
Width
=
i
EndFor
GameControls
.
SetText
(
Show_PlayList
,
">>"
)
else
For
i
=
600
To
1200
Step
5
' open
GameWindow
.
Width
=
i
EndFor
GameControls
.
SetText
(
show_PlayList
,
"<<"
)
EndIf
EndSub
Sub
Slider_Move
SX
=
gamemouse
.
MouseX
SN
=
math
.
Round
(
(
Sx
-
70
)
/
450
*
1000
)
/
10
' gets current slider position
Slider_Time_Position
=
(
SN
*
Media
.
GetLength
(
Player
)
)
/
100
' position = msec
Media
.
SetPosition
(
Player
,
Slider_Time_Position
)
' set player
EndSub
Sub
SetVolume
Media
.
SetVolume
(
Player
,
50
)
GameControls
.
SetValue
(
Volume_Control_Bar
,
50
/
10
)
EndSub
Sub
Add_List
' make dummy list (space)
For
i
=
1
To
24
Song_name
[
i
]
=
GameControls
.
AddText
(
" "
,
630
,
105
+
20
*
(
i
-
1
)
,
"Arial"
,
14
,
"False"
,
"False"
)
EndFor
GameControls
.
SetColors
(
Song_name
[
Song_Id
]
,
"red"
,
"red"
,
2
)
EndSub
Sub
Scroll
NN
=
math
.
Round
(
GameControls
.
GetValue
(
Scroller
)
+
0.5
)
For
i
=
1
To
24
S_name
=
FilePlus
.
GetFileName
(
Files_Array
[
i
+
NN
]
)
+
FilePlus
.
GetFileExtension
(
Files_Array
[
i
+
NN
]
)
If
i
+
NN
>
MM
Then
S_name
=
" "
EndIf
GameControls
.
SetText
(
Song_name
[
i
]
,
S_name
)
' sets music(movie) name + extension
If
Song_Id
=
i
+
NN
Then
GameControls
.
SetColors
(
Song_name
[
i
]
,
"red"
,
"red"
,
2
)
' current
Else
GameControls
.
SetColors
(
Song_name
[
i
]
,
"Black"
,
"Black"
,
2
)
endif
EndFor
EndSub
Sub
init
'url=program.Directory+"C:\Users\Eric\Desktop\PROPAL LECTEUR MEDIAS\BASE 1.png" ' back view partially cropped.
back
=
ImageList
.
LoadImage
(
"C:\Users\Eric\Desktop\PROPAL LECTEUR MEDIAS\BASE 2.png"
)
GameWindow
.
Width
=
1200
GameWindow
.
Height
=
606
GameWindow
.
CanResize
=
"True"
GameWindow
.
Theme
=
"XPsilver"
'"ExpressionLight"
Gback
=
GameControls
.
AddImage
(
back
,
0
,
-
10
)
GameControls
.
SetSize
(
Gback
,
1200
,
606
)
GameWindow
.
Show
(
)
EndSub
Sub
Control_button
Musicext
=
".mp3:.wma:.mp4:.avi:.wmv:.mpg:.wav:.mid:.mov"
' music movie file extensions
Scroller
=
GameControls
.
AddSlider
(
0
,
1055
-
250
,
295
,
370
,
25
)
' Scroller X position is changed by Rotation
GameControls
.
Rotate
(
Scroller
,
90
)
Seek_Bar
=
GameControls
.
AddSlider
(
0
,
160
,
455
,
400
,
22
)
' Slider for progress
Time_Box
=
GameControls
.
AddTextBox
(
"Text"
,
520
,
700
,
68
,
25
)
' time box
Volume_Control_Bar
=
GameControls
.
AddSlider
(
0
,
400
,
416
,
75
,
25
)
' volume bar
Show_PlayList
=
GameControls
.
AddButton
(
"<<"
,
525
,
413
,
36
,
30
)
' Show list mark
Stop_Button
=
GameControls
.
AddButton
(
"■"
,
280
,
413
,
30
,
30
)
' Stop button
Prev_Button
=
GameControls
.
AddButton
(
"-"
,
200
,
413
,
30
,
30
)
' Previous button
Play_Button
=
GameControls
.
AddButton
(
"▲"
,
240
,
413
,
30
,
30
)
' Play button
GameControls
.
Rotate
(
Play_Button
,
90
)
Next_Button
=
GameControls
.
AddButton
(
"+"
,
320
,
413
,
30
,
30
)
' Next button
F_Open
=
GameControls
.
AddButton
(
"▲"
,
160
,
413
,
30
,
30
)
' New file open button
PrgEnd
=
GameControls
.
addButton
(
"X"
,
69
,
80
,
30
,
30
)
' Program end button
Folder
=
GameControls
.
AddTextBox
(
"folder"
,
160
,
488
,
400
,
30
)
' TxtBox for Folder name
GameControls
.
RegisterMouseDownEvent
(
Play_Button
,
"Play_Song"
)
GameControls
.
RegisterMouseDownEvent
(
Next_Button
,
"Play_Next"
)
GameControls
.
RegisterMouseDownEvent
(
Prev_Button
,
"Play_Prev"
)
GameControls
.
RegisterMouseDownEvent
(
Stop_Button
,
"Stop_Song"
)
GameControls
.
RegisterValueChangedEvent
(
Scroller
,
"Scroll"
)
GameControls
.
RegisterMousemoveEvent
(
Seek_Bar
,
"Slider_Move"
)
GameControls
.
RegisterValueChangedEvent
(
Volume_Control_Bar
,
"Volume_Set"
)
GameControls
.
RegisterMouseDownEvent
(
Show_PlayList
,
"Show"
)
GameControls
.
RegisterMouseDownEvent
(
PrgEnd
,
"PRG_END"
)
GameControls
.
RegisterMouseDownEvent
(
F_Open
,
"Open_Files"
)
EndSub
Sub
PRG_END
Program
.
End
(
)
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.