[Gambas-user] Music.Length part 2

Ru Vuott vuott at ...325...
Wed Apr 23 20:35:27 CEST 2014


...he could get the audio file duration by using external resources of API SMPEG:


************************************************
Public Struct SMPEG_Info
  has_audio As Integer
  has_video As Integer
  width As Integer
  height As Integer
  current_frame As Integer
  current_fps As Float
  audio_string[80] As Byte
  audio_current_frame As Integer
  current_offset As Integer
  total_size As Integer
  current_time As Float
  total_time As Float
End Struct

Library "libsmpeg-0.4:0.1.4"

Private Const audio As Integer = 1

' SMPEG* SMPEG_new(const char *file, SMPEG_Info* info, int sdl_audio)
' Create a new SMPEG object from an MPEG file. This function returns a new SMPEG object.
Private Extern SMPEG_new(file$ As String, infoP As SMPEG_Info, sdl_audio As Integer) As Pointer

' void SMPEG_delete( SMPEG* mpeg )
' Delete an SMPEG object
Private Extern SMPEG_delete(mp As Pointer)


Public Sub Main()

 Dim info As New SMPEG_Info
 Dim smpeg As Pointer
 Dim fileMP3 As String


  fileMP3 = "/path/of/my/file.mp3"

  smpeg = SMPEG_new(fileMP3, info, audio)

  With info
   If .has_audio = 0 Then Error.Raise("Error: unable to load the file !")
   Print "Audio file: "; File.Name(fileMP3)
   Print "Principal characteristics: "; .audio_string.ToString()
   Print "Size: "; .total_size; " byte"
   Print "DURATION: "; Date(0, 0, 0, 0, 0, 0, .total_time * 1000)
 End With

' ...closing:
  SMPEG_delete(smpeg)

End

**********************************************

Regards
vuottttttt



--------------------------------------------
Mer 23/4/14, Benoît Minisini <gambas at ...1...> ha scritto:

 Oggetto: Re: [Gambas-user] Music.Length part 2
 A: "mailing list for gambas users" <gambas-user at lists.sourceforge.net>
 Data: Mercoledì 23 Aprile 2014, 17:51
 
 Le 23/04/2014 17:38,
 Patrik Karlsson a écrit :
 > Hi,
 >
 > it's almost 6
 years since I wrote the first post [1] regarding
 Music.Length
 > I recently picked up
 Gambas again and I am about to finish this little
 > project now. :)
 >
 > As far as I can tell, there is still no
 easy "Gambas way" to get the length
 > of an audio file, right?
 >
 > Would it be possible
 to implement such a function now?
 > It
 would be really nice to have Music.Play return the length in
 seconds as
 > float and a pure
 Music.Length function.
 >
 > In the previous thread I got some answers
 regarding command line tools, but
 > in
 this case my audio files are bundled in the project.
 >
 > /patrik
 >
 > [1]
 > http://sourceforge.net/p/gambas/mailman/gambas-user/thread/577069a50806200210i701ff536pf4e655c4cfc45ff9%40mail.gmail.com/#msg19733859
 
 You should use the gb.media
 component instead. Look at the "MediaPlayer" 
 example, it displays the length of the
 video/audio file it plays.
 
 I admit that playing a file to know its length
 is a bit stupid. It 
 should be possible to
 create a GStreamer pipe to just know the length of 
 a multimedia file without playing it.
 
 -- 
 Benoît
 Minisini
 
 ------------------------------------------------------------------------------
 Start Your Social Network Today - Download eXo
 Platform
 Build your Enterprise Intranet with
 eXo Platform Software
 Java Based Open Source
 Intranet - Social, Extensible, Cloud Ready
 Get Started Now And Turn Your Intranet Into A
 Collaboration Platform
 http://p.sf.net/sfu/ExoPlatform
 _______________________________________________
 Gambas-user mailing list
 Gambas-user at lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user




More information about the User mailing list