菜鸟别看!!!

huangjiguo8208 2003-09-17 07:06:32
急!!!!!!!!!!怎样在VB中播放MP3格式的文件???
高手帮忙!!
...全文
70 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hjj223 2003-09-20
  • 打赏
  • 举报
回复
写个mp3播放程序要这么多行代码吗?
kmzs 2003-09-20
  • 打赏
  • 举报
回复
有很多完整的范例,不过范例太完整反而不好,许多语句不知是啥用处
yunfeng007 2003-09-20
  • 打赏
  • 举报
回复
我没看,我绝对没看!
「已注销」 2003-09-20
  • 打赏
  • 举报
回复
我也是菜鸟,不过我写过MP3播放器,还可以播放MPG,AVI,RM等
xiaohuangtao 2003-09-20
  • 打赏
  • 举报
回复

我自己写了个sock类,因为WINSOCK不支持引用(做成安装盘有问题,并且不支持多线程)

超OUTLOOK软件,提供源代码
楼主: 本软件是我在业余时间完成,我的目标是将它做成国内一流的客户端邮件软件.现在初具模型

.正在修改中.它有一下特点:
1. 基于SDK模式开发
2. 大量源代码:软件中用到的所有组件,包括每一个按钮,均是自己所写.形成了自己风

格的完整的一套组件库.他们包括:列表,文件管理,菜单等
所有代码均参照标准协议写成

3. 由以下功能模块组成:邮件;新闻组;FTP;任务及其在之基础上的相应管理.如文件管

理等.
4. 合作方式:转让经营权;根据你们需要提供技术支持;作为贵公司产品发布等,我们可

以详细谈.我的联系方式是:myganlimei@163.com 13062323245

一下为该软件部分运行界面图:


安装盘下:ftp://uploads@2ccc.com/SmartMai_Setup.EXE

代码下:ftp://uploads@2ccc.com/SmartMail_Code.rar

ftp密码:uploads

建议大家先下安装盘,因为比较新,
Mars.CN 2003-09-20
  • 打赏
  • 举报
回复
晕~~~
@-@
jlum99 2003-09-17
  • 打赏
  • 举报
回复
菜鸟来了~~~~~~~~~~~
huangjiguo8208 2003-09-17
  • 打赏
  • 举报
回复
我试试,先谢了!
wingchi 2003-09-17
  • 打赏
  • 举报
回复
上面的类模块的名称应该是Mmedia
wingchi 2003-09-17
  • 打赏
  • 举报
回复
'类模块中的代码 名为Mmdia.cls
Option Explicit

Private sAlias As String ' Used internally to give an alias name to
' the multimedia resource

Private sFilename As String ' Holds the filename internally
Private nLength As Single ' Holds the length of the filename
' internally
Private nPosition As Single ' Holds the current position internally
Private sStatus As String ' Holds the current status as a string
Private bWait As Boolean ' Determines if VB should wait until play
' is complete before returning.

'note that this is all one code line:
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

Public Sub mmOpen(ByVal sTheFile As String)

' Declare a variable to hold the value returned by mciSendString
Dim nReturn As Long

' Declare a string variable to hold the file type
Dim sType As String

' Opens the specified multimedia file, and closes any
' other that may be open
If sAlias <> "" Then
mmClose
End If

' Determine the type of file from the file extension
Select Case UCase$(Right$(sTheFile, 3))
Case "WAV"
sType = "Waveaudio"
Case "AVI"
sType = "AviVideo"
Case "MID"
sType = "Sequencer"
Case "MP3"
sType = "MPEGVideo"
'sType = "MPEGVideo" 时 可以播放的不仅是Mp3音乐了.
'我只是添加了 Case "MP3" sType = "MPEGVideo",不过功能是大大加强哦.

Case Else
' If the file extension is not known then exit the subroutine
Exit Sub
End Select
sAlias = Right$(sTheFile, 3) & Minute(Now)

' At this point there is no file open, and we have determined the
' file type. Now would be a good time to open the new file.
' Note: if the name contains a space we have to enclose it in quotes
If InStr(sTheFile, " ") Then sTheFile = Chr(34) & sTheFile & Chr(34)
nReturn = mciSendString("Open " & sTheFile & " ALIAS " & sAlias _
& " TYPE " & sType & " wait", "", 0, 0)
End Sub

Public Sub mmClose()
' Closes the currently opened multimedia file

' Declare a variable to hold the return value from the mciSendString
' command
Dim nReturn As Long

' If there is no file currently open then exit the subroutine
If sAlias = "" Then Exit Sub

nReturn = mciSendString("Close " & sAlias, "", 0, 0)
sAlias = ""
sFilename = ""

End Sub

Public Sub mmPause()
' Pause playback of the file

' Declare a variable to hold the return value from the mciSendString
' command
Dim nReturn As Long

' If there is no file currently open then exit the subroutine
If sAlias = "" Then Exit Sub

nReturn = mciSendString("Pause " & sAlias, "", 0, 0)

End Sub

Public Sub mmPlay()
' Plays the currently open file, from the current position

' Declare a variable to hold the return value from the mciSendString
' command
Dim nReturn As Long

' If there is no file currently open, then exit the routine
If sAlias = "" Then Exit Sub

' Now play the file
If bWait Then
nReturn = mciSendString("Play " & sAlias & " wait", "", 0, 0)
Else
nReturn = mciSendString("Play " & sAlias, "", 0, 0)
End If
End Sub

Public Sub mmStop()
' Stop using a file totally, be it playing or whatever

' Declare a variable to hold the return value from mciSendString
Dim nReturn As Long

' If there is no file currently open then exit the subroutine
If sAlias = "" Then Exit Sub

nReturn = mciSendString("Stop " & sAlias, "", 0, 0)

End Sub

Public Sub mmSeek(ByVal nPosition As Single)
' Seeks to a specific position within the file

' Declare a variable to hold the return value from the mciSendString
' function
Dim nReturn As Long

nReturn = mciSendString("Seek " & sAlias & " to " & nPosition, "", 0, 0)

End Sub

Property Get Filename() As String
' Routine to return a value when the programmer asks the
' object for the value of its Filename property
Filename = sFilename
End Property

Property Let Filename(ByVal sTheFile As String)
' Routine to set the value of the filename property, should the programmer
' wish to do so. This implies that the programmer actually wants to open
' a file as well so control is passed to the mmOpen routine
mmOpen sTheFile
End Property

Property Get Wait() As Boolean
' Routine to return the value of the object's wait property.
Wait = bWait
End Property

Property Let Wait(bWaitValue As Boolean)
' Routine to set the value of the object's wait property
bWait = bWaitValue
End Property

Property Get Length() As Single
' Routine to return the length of the currently opened multimedia file

' Declare a variable to hold the return value from the mciSendString
Dim nReturn As Long, nLength As Integer

' Declare a string to hold the returned length from the mci Status call
Dim sLength As String * 255

' If there is no file open then return 0
If sAlias = "" Then
Length = 0
Exit Property
End If

nReturn = mciSendString("Status " & sAlias & " length", sLength, 255, 0)
nLength = InStr(sLength, Chr$(0))
Length = Val(Left$(sLength, nLength - 1))
End Property

Property Let Position(ByVal nPosition As Single)
' Sets the Position property effectively by seeking
mmSeek nPosition
End Property

Property Get Position() As Single
' Returns the current position in the file

' Declare a variable to hold the return value from mciSendString
Dim nReturn As Integer, nLength As Integer

' Declare a variable to hold the position returned
' by the mci Status position command
Dim sPosition As String * 255

' If there is no file currently opened then exit the subroutine
If sAlias = "" Then Exit Property

' Get the position and return
nReturn = mciSendString("Status " & sAlias & " position", sPosition, 255, 0)
nLength = InStr(sPosition, Chr$(0))
Position = Val(Left$(sPosition, nLength - 1))

End Property

Property Get Status() As String
' Returns the playback/record status of the current file

' Declare a variable to hold the return value from mciSendString
Dim nReturn As Integer, nLength As Integer

' Declare a variable to hold the return string from mciSendString
Dim sStatus As String * 255

' If there is no file currently opened, then exit the subroutine
If sAlias = "" Then Exit Property

nReturn = mciSendString("Status " & sAlias & " mode", sStatus, 255, 0)

nLength = InStr(sStatus, Chr$(0))
Status = Left$(sStatus, nLength - 1)

End Property
wingchi 2003-09-17
  • 打赏
  • 举报
回复
'窗体中的代码
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmMain
Caption = "Mp3Player"
ClientHeight = 4275
ClientLeft = 60
ClientTop = 450
ClientWidth = 8205
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 4275
ScaleWidth = 8205
StartUpPosition = 2 'CenterScreen
Begin VB.TextBox Text4
Height = 375
Left = 5880
TabIndex = 10
Text = "1000"
Top = 3240
Width = 855
End
Begin VB.TextBox Text3
Height = 375
Left = 360
TabIndex = 9
Top = 720
Width = 6975
End
Begin VB.TextBox Text2
Height = 375
Left = 360
TabIndex = 8
Top = 360
Width = 6975
End
Begin VB.TextBox Text1
Height = 375
Left = 360
TabIndex = 7
Top = 0
Width = 6975
End
Begin VB.CommandButton Command7
Caption = "停止"
Height = 615
Left = 4920
TabIndex = 6
Top = 1920
Width = 855
End
Begin VB.CommandButton Command6
Caption = "快近"
Height = 615
Left = 4920
TabIndex = 5
Top = 3480
Width = 855
End
Begin VB.CommandButton Command5
Caption = "快退"
Height = 615
Left = 4920
TabIndex = 4
Top = 2760
Width = 855
End
Begin VB.CommandButton Command4
Caption = "暂停"
Height = 615
Left = 3870
TabIndex = 3
Top = 1920
Width = 855
End
Begin VB.CommandButton Command3
Caption = "播放"
Height = 615
Left = 2895
TabIndex = 2
Top = 1920
Width = 855
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 1320
Top = 3360
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton Command1
Caption = "打开和播放一个媒体文件"
Height = 615
Left = 480
TabIndex = 1
Top = 1920
Width = 2172
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 500
Left = 2040
Top = 3360
End
Begin ComctlLib.ProgressBar ProgressBar1
Height = 255
Left = 360
TabIndex = 0
Top = 1440
Width = 4815
_ExtentX = 8493
_ExtentY = 450
_Version = 327682
Appearance = 1
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Multimedia As New Mmedia

Private Sub Command1_Click()

With CommonDialog1
.Filter = "Mp3 (*.mp3)|*.mp3|WaveAudio (*.wav)|*.wav|Video files (*.avi)|*.avi"
.FilterIndex = 0
.ShowOpen
End With

If CommonDialog1.Filename <> "" Then
Multimedia.Wait = False
Multimedia.mmOpen CommonDialog1.Filename
ProgressBar1.Value = 0
ProgressBar1.Max = Multimedia.Length
End If

End Sub

Private Sub Command3_Click()
Timer1.Enabled = True
Multimedia.mmPlay

End Sub

Private Sub Command4_Click()
Multimedia.mmPause
End Sub


Private Sub Command5_Click()
If Multimedia.Status <> "playing" Then Exit Sub

Dim curv As Long
Dim stepv As Long

curv = Multimedia.Position
stepv = Val(Text4.Text)

If curv - stepv > 0 Then Multimedia.mmSeek (curv - stepv): Multimedia.mmPlay

End Sub

Private Sub Command6_Click()
If Multimedia.Status <> "playing" Then Exit Sub

Dim curv As Long
Dim maxv As Long
Dim stepv As Long

curv = Multimedia.Position
maxv = Multimedia.Length
stepv = Val(Text4.Text)

If curv + stepv < maxv Then Multimedia.mmSeek (curv + stepv): Multimedia.mmPlay

End Sub


Private Sub Command7_Click()
Multimedia.mmStop
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Multimedia.mmStop
End Sub

Private Sub Timer1_Timer()
Text1.Text = Multimedia.Status
Text2.Text = Multimedia.Position
Text3.Text = Multimedia.Length

ProgressBar1.Value = Multimedia.Position

If ProgressBar1.Value = ProgressBar1.Max Then
Multimedia.mmClose
Timer1.Enabled = False
End If

End Sub

huangjiguo8208 2003-09-17
  • 打赏
  • 举报
回复
天下无人啦!!!
kmzs 2003-09-17
  • 打赏
  • 举报
回复
方法多多,网上找找

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧