تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] تشغيل ملفات صوتية في my.computer
#1
السلام عليكم يا شباب :
هل يمكن تشغيل ملفات صوتية ما عدا wav ، عن طريق
my.computer.Audio.play
ملفات بصيعة mp3 .. wma .. وغيرها
علما بأن تجربتي ومعرفتي المحدودة لم تخلض إلى نتيجة مؤكدة بالموضوع
الرد }}}
تم الشكر بواسطة:
#2
لملفات الـ mp3 128 bit rate
اضف الكلاس AudioFile وضع به 
كود :
Public Class AudioFile
   Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Int32, ByVal hwndCallback As Int32) As Int32
   Public Sub New(ByVal location As String)
       Me.Filename = location
   End Sub
   Public Sub Play()
       If _filename = "" Or Filename.Length <= 4 Then Exit Sub
       Select Case Right(Filename, 3).ToLower
           Case "mp3"
               mciSendString("open """ & _filename & """ type mpegvideo alias audiofile", Nothing, 0, IntPtr.Zero)
               Dim playCommand As String = "play audiofile from 0"
               If _wait = True Then playCommand += " wait"
               mciSendString(playCommand, Nothing, 0, IntPtr.Zero)
           Case "wav"
               mciSendString("open """ & _filename & """ type waveaudio alias audiofile", Nothing, 0, IntPtr.Zero)
               mciSendString("play audiofile from 0", Nothing, 0, IntPtr.Zero)
           Case "mid", "idi"
               mciSendString("stop midi", "", 0, 0)
               mciSendString("close midi", "", 0, 0)
               mciSendString("open sequencer!" & _filename & " alias midi", "", 0, 0)
               mciSendString("play midi", "", 0, 0)
           Case Else
               Throw New Exception("File type not supported.")
               Call Close()
       End Select
       IsPaused = False
   End Sub
   Public Sub Pause()
       mciSendString("pause audiofile", Nothing, 0, IntPtr.Zero)
       IsPaused = True
   End Sub
   Public Sub [Resume]()
       mciSendString("resume audiofile", Nothing, 0, IntPtr.Zero)
       IsPaused = False
   End Sub
   Public Sub [Stop]()
       mciSendString("stop audiofile", Nothing, 0, IntPtr.Zero)
   End Sub
   Public Sub Close()
       mciSendString("close audiofile", Nothing, 0, IntPtr.Zero)
   End Sub
   Private _wait As Boolean = False
   Public Property Wait() As Boolean
       Get
           Return _wait
       End Get
       Set(ByVal value As Boolean)
           _wait = value
       End Set
   End Property
   ReadOnly Property Milleseconds() As Integer
       Get
           Dim buf As String = Space(255)
           mciSendString("set audiofile time format milliseconds", Nothing, 0, IntPtr.Zero)
           mciSendString("status audiofile length", buf, 255, IntPtr.Zero)
           buf = Replace(buf, Chr(0), "") 'Get rid of the nulls, they muck things up
           If buf = "" Then
               Return 0
           Else
               Return CInt(buf)
           End If
       End Get
   End Property
   ReadOnly Property Status() As String
       Get
           Dim buf As String = Space(255)
           mciSendString("status audiofile mode", buf, 255, IntPtr.Zero)
           buf = Replace(buf, Chr(0), "") 'Get rid of the nulls, they muck things up
           Return buf
       End Get
   End Property
   ReadOnly Property FileSize() As Integer
       Get
           Try
               Return My.Computer.FileSystem.GetFileInfo(_filename).Length
           Catch ex As Exception
               Return 0
           End Try
       End Get
   End Property
   ReadOnly Property Channels() As Integer
       Get
           Dim buf As String = Space(255)
           mciSendString("status audiofile channels", buf, 255, IntPtr.Zero)
           If IsNumeric(buf) = True Then
               Return CInt(buf)
           Else
               Return -1
           End If
       End Get
   End Property
   ReadOnly Property Debug() As String
       Get
           Dim buf As String = Space(255)
           mciSendString("status audiofile channels", buf, 255, IntPtr.Zero)
           Return Str(buf)
       End Get
   End Property
   Private _isPaused As Boolean = False
   Public Property IsPaused() As Boolean
       Get
           Return _isPaused
       End Get
       Set(ByVal value As Boolean)
           _isPaused = value
       End Set
   End Property
   Private _filename As String
   Public Property Filename() As String
       Get
           Return _filename
       End Get
       Set(ByVal value As String)
           If My.Computer.FileSystem.FileExists(value) = False Then
               Throw New System.IO.FileNotFoundException
               Exit Property
           End If
           _filename = value
       End Set
   End Property
End Class


 وفي زر فتح الملف ضع
كود :
Dim x As New OpenFileDialog
       x.Filter = "|*.mp3"
       If x.ShowDialog = Windows.Forms.DialogResult.OK Then

           Dim audio As New AudioFile(x.FileName)
           audio.Close()
           audio.Play()
       End If
الرد }}}
تم الشكر بواسطة: محمود رغمان
#3
شكرا أخي HASAN6.0 على هذا الجهد
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  مرفق سورس كود ارسال ملفات الى الواتس بدون API new_programer 0 49 14-04-24, 02:16 PM
آخر رد: new_programer
  [سؤال] كيفية تشغيل ملف باتش دون ظهور "نافذةالـ Consol "؟ AmeenRashed 9 681 14-12-23, 12:07 PM
آخر رد: asmarsou
Information [VB.NET] أنواع ملفات التحديث أبو خالد الشكري 2 223 15-11-23, 12:00 PM
آخر رد: أبو خالد الشكري
  تشغيل الماكرو عن طريق اكواد الفجوال نيمو 0 271 03-11-23, 11:14 AM
آخر رد: نيمو
  [VB.NET] أين الخطأ فى تشغيل هذا التطبيق AhmedEissa 0 242 27-10-23, 04:05 PM
آخر رد: AhmedEissa
  تشغيل برنامج خارجي ضمن شاشة برنامجي strongriseman 1 375 13-09-23, 10:14 PM
آخر رد: anes
  استفسار عن تشغيل قاعدة البيانات بالبرنامج عند العميل محمد ابوخليل 1 371 10-09-23, 07:09 PM
آخر رد: Asem2
  مساعده في تشغيل اكثرمن فورم في وقت واحد maherhaddaf 5 534 19-07-23, 03:28 PM
آخر رد: Taha Okla
  [سؤال] تشغيل راديو عن طريق الانترنت أبوسعود 5 728 01-07-23, 10:34 PM
آخر رد: asmarsou
  التحقق من معطيات قبل تشغيل البرنامج ابو محمد محمد محمد 3 511 30-04-23, 11:03 PM
آخر رد: عبدالله الدوسري

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم