Android Example Create wave form

You can generate waveform from peaks json file which is generated from mp3 file.
In this source waveforms has drown with canvas.
You can customize everything about waveforms display with this source.

Screenshot_20171117-143611.jpg



B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 900
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private x As Float
    Dim Drawlinewave As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
   
    Dim Steper As Float
    Dim pointer,counter,tedad As Float
    Dim avrg ,avergcount As Int
    pointer = 0
    counter = 0
    Drawlinewave.Initialize(Activity)
    x=0
    Log("Downloaded")
    Dim json As String
   
    json = File.ReadString(File.DirAssets,"S243_1099_sJRDZFN4.js")
   
    Dim parser As JSONParser
    parser.Initialize(json)
    Dim root As Map = parser.NextObject
    Dim waves As List = root.Get("peaks")

           
    Log("Screen: " & 100%x)
    Log("waves count: " & waves.Size )
    Steper = Round( waves.Size / 100%x)
       
    Steper = Steper * 8
    tedad =100%x / (waves.Size  / Steper)
    Log("tedad: " & tedad )
    Log("Steper: " & Steper )
    avergcount = Steper/10
    For i=0 To waves.Size-1 Step Steper
        avrg = 0
        For r = 0 To avergcount
            avrg = avrg + waves.Get(i+r)
        Next
        avrg = avrg / avergcount
        drawwave(avrg,tedad)
    Next
   
End Sub
     

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
   
End Sub
Sub Jobdone(Job As HttpJob)
End Sub

Sub drawwave(value    As Int,tedad As Float)
    value = value-20
    If value>180 Then value=value - 30
    Drawlinewave.DrawLine(x,70dip,x,140dip-(value),Colors.White,2dip)
    'Drawlinewave.DrawLine(x,300,x,200+value,Colors.Yellow,1dip)
    x=x+ tedad
End Sub


you can custom to ratio and Number wave in line with number 10 and 8

B4X:
  Steper = Steper * 8
    tedad =100%x / (waves.Size  / Steper)
    Log("tedad: " & tedad )
    Log("Steper: " & Steper )
    avergcount = Steper/10
 

Attachments

  • s243_1099_sjrdzfn4.zip
    3.3 KB · Views: 349
Top