Results 1 to 8 of 8

Thread: repeat music and pause music

  1. #1

    Thread Starter
    Member dorbian's Avatar
    Join Date
    Apr 2002
    Location
    amsterdam - netherlands
    Posts
    62

    repeat music and pause music

    he dude's i want to repeat music with a click on a button i don't know the option i also want to know how to use the pause option when i use it and press play or something like that it starts all over again so please help me with this problem
    thanx...

  2. #2

    Thread Starter
    Member dorbian's Avatar
    Join Date
    Apr 2002
    Location
    amsterdam - netherlands
    Posts
    62
    bounce really need some help dude's

  3. #3
    Addicted Member
    Join Date
    Apr 2002
    Posts
    237
    Which Control are you using, MediaPlayer or RealPlayer?

  4. #4

    Thread Starter
    Member dorbian's Avatar
    Join Date
    Apr 2002
    Location
    amsterdam - netherlands
    Posts
    62
    mediaplayer based sorry forgot to mention it mb

  5. #5
    Addicted Member
    Join Date
    Apr 2002
    Posts
    237
    Creat three Command Buttons ... Play, Pasue, and Replay ...and use the below code...I hope it helps you


    Private Sub Command1_Click()
    'Set PlayCount to 0 to repeat playing
    MediaPlayer1.PlayCount = 0
    MediaPlayer1.Open "c:\mymusic\music.wav"
    End Sub

    Private Sub Command2_Click()
    'Pause
    MediaPlayer1.Pause
    End Sub

    Private Sub Command3_Click()
    'Continue playing
    MediaPlayer1.Play
    End Sub

  6. #6

    Thread Starter
    Member dorbian's Avatar
    Join Date
    Apr 2002
    Location
    amsterdam - netherlands
    Posts
    62
    i already tried that and it didn't work ( weird huh ) but nmow it works thanx alot althoug i dont know what i did wrong

  7. #7
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    It's a lot better not to use MediaPlayer, it's slow and eats a heluvalodov memory. Use this routine instead, put it in a module.

    I know it's quite a bit of work and kinda hard to figure out, bt it's defenately worth it!

    VB Code:
    1. 'Module MPEG,AVI,sequencer,audio source code
    2. 'All Functions in this Module will return a value
    3. 'if the Function success or not.
    4.  
    5. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    6. Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
    7. Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    8. Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    9. Private Type RECT
    10.         Left As Long
    11.         Top As Long
    12.         Right As Long
    13.         Bottom As Long
    14. End Type
    15. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    16. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    17. Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    18. Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    19. Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    20. Dim glo_hWnd As Long
    21. Dim glo_from As Long
    22. Dim glo_to As Long
    23.  
    24. Public Function OpenMPEG(hwnd As Long, Filename As String, TypeDevice As String) As String
    25. 'Callig OpenMPEG will open the multimedia file
    26. 'Parameters
    27. 'hWnd
    28. '[in]handle of the window
    29. 'which you want to play in. you can put handle for
    30. 'your desktop if you want to playing movie in your desktop.
    31.  
    32. 'filename
    33. '[in]Specifies file name and the path it can contain any space
    34. 'which you want to play.
    35.  
    36. 'typeDevice
    37. '[in] Specifies a type of MCI device and it could be from the following:
    38. 'Type MCI       description                     driver file
    39. 'sequencer      dealing with mid                mciseq.drv
    40. '               files
    41. 'MPEGVideo      dealing with most multimedia    mciqtz.drv
    42. '               like mpg,mp3,mp2..
    43. '               au,aiff,..etc also support
    44. '               avi,vob(for DVD),midi,mid
    45. '               and rmi files.because of this
    46. '               my advice to you to use
    47. '               type "MPEGVideo" to playing
    48. '               MOST FILES even avi!!
    49. '               I got this info from my
    50. '               experiment when I opened
    51. '               System.ini in section MCI
    52. '               Then I must share others.
    53. 'avivideo       deling with avi movie           mciavi.drv
    54.  
    55. 'the following types if you had ATI RAGE II or Later
    56. '(This VGA Card to Support DVD Video)
    57.  
    58. 'DvdVideo       This support DVD's Video        MciCinem.drv DVD
    59. 'ATIMPEGVIDEO   to playing MPEG Video           mciatim1.drv
    60.  
    61. 'But my advice to you to not use type "ATIMPEGVIDEO" & "DvdVideo" because
    62. 'Type MPEGVideo can support most Multimedia files and also support DVD's
    63. 'Video if you had ATI RAGE II or LATER.
    64. 'last note for DVD Video: you must have a fast computer
    65.  
    66. 'note : Type "MpegVideo" support these extensions:
    67. 'qt , mov, dat,snd, mpg, mpa, mpv, enc, m1v, mp2,mp3, mpe, mpeg, mpm
    68. 'au , snd, aif, aiff, aifc,wav,wmv,wma,avi,midi,mid,rmi,avi,etc.
    69.  
    70. 'Note if there are any new type in (system.ini in windows 98 or in registry in windows 2000)
    71. 'it will supported by Type "MPEGVideo" because of this use type "MPEGVideo" to playing
    72. 'Most Files and remember you can use sequencer for mid and avivideo for avi,,etc.
    73.  
    74. 'Now you must note using Type "MPEGVideo" can playing all Multimedia files
    75.  
    76. 'Note : if this Function success will return value string "Success"
    77. 'or if not will return value string description the error which occur
    78.  
    79. 'Okay make sure if you used this function don't forget to use function
    80. 'CloseMPEG When you will end your program or you
    81. 'will got error message
    82.  
    83. Dim cmdToDo As String * 255
    84. Dim dwReturn As Long
    85. Dim ret As String * 128
    86.  
    87. Dim tmp As String * 255
    88. Dim lenShort As Long
    89. Dim ShortPathAndFie As String
    90. lenShort = GetShortPathName(Filename, tmp, 255)
    91. ShortPathAndFie = Left$(tmp, lenShort)
    92.  
    93.    
    94. glo_hWnd = hwnd
    95. cmdToDo = "open " & ShortPathAndFie & " type " & TypeDevice & " Alias mpeg parent " & hwnd & " Style 1073741824"
    96. dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&)
    97.  
    98.  
    99. If Not dwReturn = 0 Then  'not success
    100.     mciGetErrorString dwReturn, ret, 128
    101.     OpenMPEG = ret: OpenMPEG = "Type not Supported!": Exit Function
    102. End If
    103.    
    104. OpenMPEG = "Success"
    105. End Function
    106.  
    107. Public Function PlayMPEG(from_where As String, to_where As String) As String
    108. 'calling PlayMPEG will playing the multimedia file
    109. 'the first parameter for from where playing file
    110. 'the second parameter for to where playing file
    111. 'if the first parameter is vbNullString and the second parameter is vbNullString the Function Will:
    112. 'playing from the beginning to end.
    113. 'if the first parameter is 10 and the second parameter is 100 the Function Will:
    114. 'playing from 10 to 100 and stop.
    115. 'if the first parameter is vbNullString and the second parameter is 100 the Function Will:
    116. 'playing from the beginning to 100 and stop.
    117. 'if the first parameter is 104 and the second parameter is vbNullString the Function Will:
    118. 'playing from 104 to end.
    119. 'Note :the numbers 10,100,104 is an example for from playing to where end playing
    120.  
    121. 'Note : if this Function success will return value string "Success"
    122. 'or if not will return value string description the error which occur
    123.  
    124. If from_where = vbNullString And to_where = vbNullString Then
    125. glo_from = 1
    126. glo_to = GetTotalFrames
    127. ElseIf Not from_where = vbNullString And Not to_where = vbNullString Then
    128. glo_from = from_where
    129. glo_to = to_where
    130. ElseIf Not from_where = vbNullString And to_where = vbNullString Then
    131. glo_from = from_where
    132. glo_to = GetTotalFrames
    133. ElseIf from_where = vbNullString And Not to_where = vbNullString Then
    134. glo_from = 1
    135. glo_to = to_where
    136. End If
    137.  
    138. Dim cmdToDo As String * 255
    139. Dim dwReturn As Long
    140. Dim ret As String * 128
    141. cmdToDo = "play mpeg from " & glo_from & " to " & glo_to
    142.  
    143. dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&)
    144.  
    145. If Not dwReturn = 0 Then  'not success
    146.     mciGetErrorString dwReturn, ret, 128
    147.     PlayMPEG = ret
    148.     Exit Function
    149. End If
    150.  
    151. PlayMPEG = "Success"
    152. End Function
    153.  
    154. Public Function CloseMPEG() As String
    155. 'calling CloseMPEG will close the multimedia file
    156. 'you must call this function if you call OpenMPEG
    157. 'And want to close your program or you will get an
    158. 'error message
    159.  
    160. 'Note : if this Function success will return value string "Success"
    161. 'or if not will return value string description the error which occur
    162.  
    163. Dim dwReturn As Long
    164. Dim ret As String * 128
    165. dwReturn = mciSendString("Close mpeg", 0&, 0&, 0&)
    166.  
    167. If Not dwReturn = 0 Then  'not success
    168.     mciGetErrorString dwReturn, ret, 128
    169.     CloseMPEG = ret
    170.     Exit Function
    171. End If
    172.  
    173. CloseMPEG = "Success"
    174. End Function
    175.  
    176. Public Function PauseMPEG() As String
    177. 'calling PauseMPEG will pause the multimedia file
    178.  
    179. 'Note : if this Function success will return value string "Success"
    180. 'or if not will return value string description the error which occur
    181.  
    182. Dim dwReturn As Long
    183. Dim ret As String * 128
    184. dwReturn = mciSendString("Pause mpeg", 0&, 0&, 0&)
    185.  
    186. If Not dwReturn = 0 Then  'not success
    187.     mciGetErrorString dwReturn, ret, 128
    188.     PauseMPEG = ret
    189.     Exit Function
    190. End If
    191.    
    192. PauseMPEG = "Paused"
    193. End Function
    194.  
    195. Public Function StopMPEG() As String
    196. 'calling StopMPEG will Stop the multimedia file
    197.  
    198. 'Note : if this Function success will return value string "Success"
    199. 'or if not will return value string description the error which occur
    200.  
    201. Dim dwReturn As Long
    202. Dim ret As String * 128
    203. dwReturn = mciSendString("Stop mpeg", 0&, 0&, 0&)
    204.  
    205. If Not dwReturn = 0 Then  'not success
    206.     mciGetErrorString dwReturn, ret, 128
    207.     StopMPEG = ret
    208.     Exit Function
    209. End If
    210.  
    211. StopMPEG = "Success"
    212. End Function
    213.  
    214. Public Function ResumeMPEG() As String
    215. 'calling ResumeMPEG will Resume the multimedia file
    216.  
    217. 'Note : if this Function success will return value string "Success"
    218. 'or if not will return value string description the error which occur
    219.  
    220. Dim dwReturn As Long
    221. Dim ret As String * 128
    222. dwReturn = mciSendString("Resume mpeg", 0&, 0&, 0&)
    223.  
    224. If Not dwReturn = 0 Then  'not success
    225.     mciGetErrorString dwReturn, ret, 128
    226.     ResumeMPEG = ret
    227.     Exit Function
    228. End If
    229.  
    230. ResumeMPEG = "Success"
    231. End Function
    It continues in the next post, cos it's too long...
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  8. #8
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    VB Code:
    1. Public Function GetStatusMPEG() As String
    2. 'Calling Function GetStatusMPEG
    3.  
    4. 'Note : if this Function success will return value string
    5. '(the status of multimedia file) if it "playing" or "paused" or "stopped"
    6. 'or if not will return value string "ERROR"
    7.  
    8.  
    9. 'also you can exame the status like this: you can copy it
    10. 'Dim Result As String
    11. 'Result = GetStatusMPEG
    12. 'If Result = "ERROR" Then 'this mean failed then write your commands here
    13. ''.....
    14. ''....
    15. ''..
    16. 'ElseIf Result = "playing" Then 'this mean it now playing .ok write your commands here
    17. ''....
    18. ''...
    19. ''..
    20. 'ElseIf Result = "stopped" Then 'this mean it now stopped .ok write your commands here
    21. ''....
    22. ''...
    23. ''..
    24. 'ElseIf Result = "paused" Then 'this mean it now paused .ok write your commands here
    25. ''....
    26. ''...
    27. ''..
    28.  
    29. 'End If
    30.  
    31.  
    32. Dim dwReturn As Long
    33. Dim status As String * 255
    34. Dim ret As String * 255
    35.  
    36. dwReturn = mciSendString("status mpeg mode", status, 255, 0&)
    37.  
    38. If Not dwReturn = 0 Then  'not success
    39.     GetStatusMPEG = "ERROR"
    40.     Exit Function
    41. End If
    42.  
    43. ' haha what you think why I wirte these below lines
    44. Dim i As Integer
    45. Dim CharA As String
    46. Dim RChar As String
    47. RChar = Right$(status, 1)
    48. For i = 1 To Len(status)
    49.     CharA = Mid(status, i, 1)
    50.     If CharA = RChar Then Exit For
    51.     GetStatusMPEG = GetStatusMPEG + CharA
    52. Next i
    53. ' the answer : to get just the string to we wanna make compare in future like this:
    54. ' if GetStatusMPEG = "playing" then msgbox "Now plying"
    55. End Function
    56.  
    57. Public Function GetTotalFrames() As Long
    58. 'calling GetTotalframes will Get the Total frames for
    59. 'the multimedia file
    60.  
    61. 'Note : if this Function success will return value long
    62. 'is "number of total frames"
    63. 'or if not will return value long is -1
    64.  
    65. Dim dwReturn As Long
    66. Dim Total As String * 255
    67.  
    68. dwReturn = mciSendString("set mpeg time format frames", Total, 255, 0&)
    69. dwReturn = mciSendString("status mpeg length", Total, 255, 0&)
    70.  
    71. If Not dwReturn = 0 Then  'not success
    72.     GetTotalFrames = -1
    73.     Exit Function
    74. End If
    75.  
    76. GetTotalFrames = Val(Total)
    77. End Function
    78.  
    79. Public Function GetTotalTimeByMS() As Long
    80. 'calling GetTotalTimeByMS will Get the Total time by
    81. 'millisecond for the multimedia file
    82.  
    83. 'Note : if this Function success will return value long
    84. 'is "the Total time by millisecond"
    85. 'or if not will return value long is -1
    86.  
    87. Dim dwReturn As Long
    88. Dim TotalTime As String * 255
    89.  
    90.  
    91. dwReturn = mciSendString("set mpeg time format ms", Total, 255, 0&)
    92. dwReturn = mciSendString("status mpeg length", TotalTime, 255, 0&)
    93.  
    94. mciSendString "set mpeg time format frames", Total, 255, 0& ' return focus to frames not to time
    95.  
    96. If Not dwReturn = 0 Then  'not success
    97.     GetTotalTimeByMS = -1
    98.     Exit Function
    99. End If
    100.  
    101. GetTotalTimeByMS = Val(TotalTime)
    102. End Function
    103.  
    104. Public Function MoveMPEG(to_where As Long) As String
    105. 'calling MoveMPEG will seek (change the position)for
    106. 'the multimedia file
    107. 'it need just one parameter for to where want to change
    108. 'position (must be number of frame you want to go to)
    109.  
    110. 'Note : if this Function success will return value string "Success"
    111. 'or if not will return value string description the error which occur
    112.  
    113. Dim dwReturn As Long
    114. Dim ret As String * 255
    115.  
    116. dwReturn = mciSendString("seek mpeg to " & to_where, 0&, 0&, 0&)
    117. mciSendString "Play mpeg", 0&, 0&, 0&
    118.  
    119. If Not dwReturn = 0 Then  'not success
    120.     mciGetErrorString dwReturn, ret, 128
    121.     MoveMPEG = ret
    122.     Exit Function
    123. End If
    124. MoveMPEG = "Success"
    125. End Function
    126.  
    127. Public Function GetCurrentMPEGPos() As Long
    128. 'Calling Function GetCurrentMPEGPos
    129. 'the returned value from this function is number of current frame
    130. 'and if the function failed will return value -1
    131.  
    132.  
    133. Dim dwReturn As Long
    134. Dim pos As String * 255
    135.  
    136. dwReturn = mciSendString("status mpeg position", pos, 255, 0&)
    137.  
    138. If Not dwReturn = 0 Then  'not success
    139.     GetCurrentMPEGPos = -1
    140.     Exit Function
    141. End If
    142.  
    143. GetCurrentMPEGPos = Val(pos)
    144. End Function
    145.  
    146. Public Function PutMPEG(Left As Long, Top As Long, Width As Long, Height As Long) As String
    147. 'Calling PutMPEG will resize the move and :
    148. 'if you are set parameter width or Height zero
    149. 'the function will get the actual size of the window which
    150. 'want to play in and resize the movie to fit the window
    151.  
    152. 'Note : if this Function success will return value string "Success"
    153. 'or if not will return value string description the error which occur
    154.  
    155. Dim dwReturn As Long
    156. Dim ret As String * 255
    157. If Width = 0 Or Height = 0 Then
    158.     Dim rec As RECT
    159.     Call GetWindowRect(glo_hWnd, rec)
    160.     Width = rec.Right - rec.Left
    161.     Height = rec.Bottom - rec.Top
    162. End If
    163.  
    164. dwReturn = mciSendString("put mpeg window at " & Left & " " & Top & " " & Width & " " & Height, 0&, 0&, 0&)
    165.  
    166. If Not dwReturn = 0 Then  'not success
    167.     mciGetErrorString dwReturn, ret, 128
    168.     PutMPEG = ret
    169.     Exit Function
    170. End If
    171.  
    172. PutMPEG = "Success"
    173. End Function
    174. Public Function GetPercent() As Long
    175. 'Calling Function GetPercent
    176. 'the returned value from this function is Percent "Progress"
    177. 'if it successed and if the function failed will return value -1
    178.  
    179. On Error Resume Next
    180. Dim TotalFrames As Long
    181. Dim CurrFrame As Long
    182. TotalFrames = GetTotalFrames
    183. CurrFrame = GetCurrentMPEGPos
    184.  
    185. If TotalFrames = -1 Or CurrFrame = -1 Then
    186. GetPercent = -1
    187. Exit Function
    188. End If
    189.  
    190. GetPercent = CurrFrame * 100 / TotalFrames
    191. End Function
    192. Public Function GetFramesPerSecond() As Long
    193. 'this Function Will return amount frames per second if it
    194. 'Success or if not will return value -1
    195. Dim TotalFrames As Long
    196. Dim TotalTime As Long
    197. TotalTime = GetTotalTimeByMS
    198. TotalFrames = GetTotalFrames
    199. If TotalFrames = -1 Or TotalTime = -1 Then
    200.     GetFramesPerSecond = -1
    201.     Exit Function
    202. End If
    203. GetFramesPerSecond = TotalFrames / (TotalTime / 1000)
    204. End Function
    205. Public Function AreMPEGAtEnd() As Boolean
    206.  
    207. 'Note:I used API callback to make callback and opreator
    208. 'AddressOf but the program will be very slow because of this
    209. 'I removed that way and I used this way
    210.  
    211.  
    212. 'This Function will tell if multimedia file now at end
    213. 'to use this Function put it in a timer and set Interval
    214. 'for a timer = 100 and make the timer false and after Play
    215. 'Multimedia files Successfully set the timer true.
    216. 'The Commands Which you will put it in a timer the Following:
    217.  
    218.  
    219. 'Copy the Following in a timer
    220. 'If AreMPEGAtEnd = True Then
    221. ''this mean  file multimedia at the end now then
    222. ''write your commnad here or call you favourit Fucntion
    223. ''or even you can play the file again or paly the next file
    224. ''if you had a list of multimedia files.
    225. '.....
    226. '...
    227. '..
    228. 'if you wanna know if the multimedia file
    229. 'at the end now don't use option Auto Repeat
    230. 'you must do auto repeat by yourself by the following command
    231. 'in this place after make the previous compare (I mean afyer compare in a timer)
    232.  
    233. 'Result = PlayMPEG(txtFrom, TxtTo)
    234. 'or you have choice to close this File and open
    235. 'another file and play it( this if had a list of files)
    236. 'like this command after make the previous compare(I mean afyer compare in a timer)
    237. 'Dim Result As String
    238. 'Result = CloseMPEG
    239. 'Result = OpenMPEG(FrameVideo.hwnd, filename, typeDevice) 'call now function openMPEG
    240. 'Result = PlayMPEG(txtFrom, TxtTo)
    241.  
    242. 'TimerName.Enabled = False ' and remeber don't forget
    243. 'write this line becuase you got what you want then
    244. 'Close the timer.Okay.
    245. 'Else
    246. 'this mean result calling function false and this mean the
    247. 'multimedia file not at the end now
    248. '....
    249. '...
    250. '..
    251.  
    252. 'End If
    253.  
    254. Dim currpos As Long
    255. currpos = Val(GetCurrentMPEGPos)
    256. If glo_to = currpos Or (glo_to - 1) < currpos Then
    257. AreMPEGAtEnd = True
    258. Else
    259. AreMPEGAtEnd = False
    260. End If
    261. End Function
    That's it.
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width