Android Question problem with sleep()

rahemdavari

New Member
i have page and play some voice files and video files in that but after some minutes i lost the voice of files! and after some minutes in mute form return the voice in normal as first. i send a peace of my page code above:
play some video and voice:
    Dim oldposition As Int =0
                Dim cartontimeuse As Long = Main.cfromr*60
                For y=0 To Main.classpr
                    Dim cartonid As Int =0
                    Dim newposition As Int =0
                    For x=0 To Main.chlist.Size -1
                        Dim elapsedTime As Long = GetElapsedTime
                        Log("زمان گذشته در showclass: " & elapsedTime & " ثانیه")
                    
                        
                        If elapsedTime>cartontimeuse Then
                            cartontimeuse=(elapsedTime)+(Main.ctimer*60)+(Main.cfromr*60)
                            pm.KeepAlive(True) ' جلوگیری از sleep دستگاه
                        
                            If nextcarton=1 Then
                                cartonid=cartonid+1
                                newposition=0
                            Else
                            End If
                            If cartonid>Main.SelectedCartons.Size-1 Then
                                cartonid=0
                            End If
                            If def<deftime Then
                                sleeptime=(videoduration-newposition)
                                nextcarton=1
                                    
                                    
                            Else
                                sleeptime=(Main.ctimer*60000)
                                nextcarton=0
                            End If

                            'For i=0 To Main.SelectedCartons.Size-1
                                
                            '    Sleep(3000)
                            video.RemoveView
                            video.Initialize("")
                            Activity.AddView(video,0,0,100%x,100%y)
                            curcarton=sql1.ExecQuery("Select * From carton Where cartonid = "&Main.SelectedCartons.Get(cartonid))
                            curcarton.Position=0
                            Dim cfile1 As String
                            cfile1=curcarton.GetString("cartonfilename")
                            If File.Exists(File.DirInternal,cfile1)=True Then
                                '    Sleep(5000)
                                video.LoadVideo(File.DirInternal,cfile1)
                                'Sleep(5000)
                                video.BringToFront
                        
                                video.Width=100%x
                                video.Height=100%y
                                video.Left=5%x
                                video.Top=0
                                video.MediaControllerEnabled=False
                                video.Position=newposition
                                newposition=newposition+(Main.ctimer*60000)
                                video.Play
                                Sleep(5000)
                                Dim videoduration As Int = video.Duration
                                def =videoduration-newposition
                                deftime=Main.ctimer*60000
                                
                                Sleep(sleeptime)
                            
                            
                                video.Stop
                                video.RemoveView
                                    
                                
                                'Exit
                            End If
                            '    Next
                
                            
                        Else
                        
                        End If
                        cur1= sql1.ExecQuery("Select * From VoiceAndImage Where vid = "&Main.chlist.Get(x))
                        cur1.Position=0
                    
                    
                        For j=0 To Main.filepr-1
                    
                            Panel12.AddView(homekey,40%x,93%y,20%x,20%x)
                            Panel12.AddView(classbg,0,0,100%x,100%y)
                            Dim mgbmpp As Bitmap
                            mgbmpp.Initialize(File.DirInternal, "homekey.png")
    
                            Dim mgbdp As BitmapDrawable
                            mgbdp.Initialize(mgbmpp)
                            homekey.Background=mgbdp
                        player.Initialize
                            '        classbg.SendToBack
                            player.Initialize2(vfilename11&".m4a")
                            lbl12.Initialize("")
        
                        
                            lbl12.Initialize("")
                            img12.Initialize("imgItem")
        
        
    
                            vfilename11=cur1.GetString("vfile")
                            fid11 = cur1.GetInt("vid")
                            vimagename11=cur1.GetString("vimage")
'    voicefiles11.Add(vfilename11)

                            Panel12.AddView(img12,25%x,25%y,60%x,60%x)

                            If vimagename11 <> Null Then
                                img12.Gravity=Gravity.FILL
        
                                img12.Bitmap=LoadBitmap(RecordDir,vimagename11&".jpg")
                                img12.Invalidate
            
                            Else
                                img12.Bitmap=LoadBitmap(File.DirInternal, "default_image.jpg")
                            End If
                            Panel12.AddView(lbl12,25%x,65%y,70%x,10%y)
                            lbl12.TextColor=Colors.Black
        
                            lbl12.TextSize=46
                            lbl12.Gravity=Gravity.CENTER
                            lbl12.Text=cur1.GetString("vname")
                        
                            '
'                        Dim elapsedTime As Long = GetElapsedTime
'                        Log("زمان گذشته در showclass: " & elapsedTime & " ثانیه")
                            If vfilename11 <> Null Then
        
        
        
                                Sleep(3000)
                                player.Load(RecordDir, vfilename11&".m4a")
                                player.Play
                                
                                Sleep(4000)
                                Panel12.RemoveAllViews
        
                            End If
                            
                        Next
        

                    Next
                Next
                'end cendr
            End If
        Else
            
            'end selectedcarton
        End If
 

Peter Simpson

Expert
Licensed User
Longtime User
I'm not convinced that you know 100% how the flow of sleep works. Read the Resumable Subs - Sleep / Wait For tutorial in the link below by Erel.

 
Upvote 0
Top