?
Solved

Parsing .wav files using Visual Basic .net and Windows Media Player.

Posted on 2005-04-26
3
Medium Priority
?
317 Views
Last Modified: 2012-06-22
I have Windows XP professional and Visual Studio.net Professional version 2003 software.
Using Visual Basic .net I added a form and embedded the Windows Media Player version 9 control.
I am able to play back .wav files but what I'd like to do is be able to parse a .wav (or any media file) by time.  

For example:  If I had a .wav file that was 4 seconds long and I wanted to parse out 2-3 seconds in the middle and make that a separate file (without damaging the orignal .wav file).  How would I do that?

Thank you for any help you can give me.
0
Comment
Question by:tjgilbert
1 Comment
 
LVL 27

Accepted Solution

by:
planocz earned 1000 total points
ID: 13866708
Here is a sample on playing parts of a file, might help in separating the file....


'FORM 1

Public Class frmPlayApart
    Inherits System.Windows.Forms.Form
    Private Declare Function mciGetErrorString Lib "MMSYSTEM.DLL" (ByVal errornum As Integer, ByVal ErrorString As String, ByVal errorsize As Short) As Short
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
    Private voicefile As String = "c:\waves\MYWAVE.wav"  '<---Wave file used for sound

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents rbn1 As System.Windows.Forms.RadioButton
    Friend WithEvents rbn2 As System.Windows.Forms.RadioButton
    Friend WithEvents rbn3 As System.Windows.Forms.RadioButton
    Friend WithEvents rbn4 As System.Windows.Forms.RadioButton
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.rbn4 = New System.Windows.Forms.RadioButton
        Me.rbn3 = New System.Windows.Forms.RadioButton
        Me.rbn2 = New System.Windows.Forms.RadioButton
        Me.rbn1 = New System.Windows.Forms.RadioButton
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.rbn4)
        Me.GroupBox1.Controls.Add(Me.rbn3)
        Me.GroupBox1.Controls.Add(Me.rbn2)
        Me.GroupBox1.Controls.Add(Me.rbn1)
        Me.GroupBox1.Location = New System.Drawing.Point(24, 20)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(184, 160)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "GroupBox1"
        '
        'rbn4
        '
        Me.rbn4.Location = New System.Drawing.Point(12, 108)
        Me.rbn4.Name = "rbn4"
        Me.rbn4.Size = New System.Drawing.Size(116, 24)
        Me.rbn4.TabIndex = 3
        Me.rbn4.Text = "Play 700 to 1000"
        '
        'rbn3
        '
        Me.rbn3.Location = New System.Drawing.Point(12, 80)
        Me.rbn3.Name = "rbn3"
        Me.rbn3.TabIndex = 2
        Me.rbn3.Text = "Play 400 to 600"
        '
        'rbn2
        '
        Me.rbn2.Location = New System.Drawing.Point(12, 52)
        Me.rbn2.Name = "rbn2"
        Me.rbn2.TabIndex = 1
        Me.rbn2.Text = "Play 100 to 200"
        '
        'rbn1
        '
        Me.rbn1.Location = New System.Drawing.Point(12, 20)
        Me.rbn1.Name = "rbn1"
        Me.rbn1.TabIndex = 0
        Me.rbn1.Text = "Play 0 to 100"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(32, 204)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 4
        Me.Button1.Text = "Start"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(136, 204)
        Me.Button2.Name = "Button2"
        Me.Button2.TabIndex = 4
        Me.Button2.Text = "End"
        '
        'Form2
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(252, 273)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Button2)
        Me.Name = "Form2"
        Me.Text = "Form2"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Function ReadWaveArea(ByVal digit As Short) As Short
        Dim x As Integer

        Select Case digit
            Case 0 : x = mciSendString("play voice from 0 to 100 wait", CStr(0), 0, 0)
            Case 1 : x = mciSendString("play voice from 100 to 200 wait", CStr(0), 0, 0)
            Case 2 : x = mciSendString("play voice from 400 to 600 wait", CStr(0), 0, 0)
            Case 3 : x = mciSendString("play voice from 700 to 1000 wait", CStr(0), 0, 0)
        End Select
    End Function
    Private Sub InitializeWave()
        Dim sCmd As String
        Dim x, r As Integer
        Dim StrLen As Short
        Dim ErrorString As String

        FileOpen(1, voicefile, OpenMode.Binary)
        FileClose(1)
        On Error GoTo 0
        sCmd = "open " & voicefile & " type waveaudio alias voice"
        x = mciSendString(sCmd, CStr(0), 0, 0)
        If x <> 0 Then
            StrLen = 255
            r = mciGetErrorString(x, ErrorString, StrLen)
            MsgBox(ErrorString)
            End
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim res As Short
        Dim x As Integer

        InitializeWave()
        If rbn1.Checked = True Then
            res = ReadWaveArea(0)
        ElseIf rbn2.Checked = True Then
            res = ReadWaveArea(1)
        ElseIf rbn3.Checked = True Then
            res = ReadWaveArea(2)
        ElseIf rbn4.Checked = True Then
            res = ReadWaveArea(3)
        End If
        x = mciSendString("close voice", CStr(0), 0, 0)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
End Class
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question