android - App crashing while calling another function which contains plyer audio methods -
actually made app detects shaking of device , responds. responds when give command change label.text names or when call function contains audio recording functions crashes. here code:-
from kivy.app import app kivy.lang import builder kivy.clock import clock plyer import accelerometer kivy.uix .relativelayout import relativelayout kivy.properties import objectproperty, numericproperty builder.load_string(""" <accel>: boxlayout: orientation:'vertical' label: id: x_val text: 'x:' label: id: y_val text: 'y:' label: id: z_val text: 'z:' label: id: x_tst text: 'value:' boxlayout: size_hint_y: none height: '48dp' padding: '4dp' togglebutton: id: start_btn text: 'start accelerometer' on_press: root.accelerometer() """) class accel(relativelayout): audio = objectproperty() time = numericproperty() has_record = false def __init__(self): super(accel, self).__init__() self.sensorenabled=false self.counter=0 self.x_axis=[0,0,0,0,0] self.pan=0 def record(self): state = self.audio.state if state == 'ready': self.audio.start() self.ids.x_tst.text = "recording started" def accelerometer(self): if not self.sensorenabled: accelerometer.enable() clock.schedule_interval(self.accelerate, 1/5) self.sensorenabled =true self.ids.start_btn.text="stop" else: accelerometer.disable() clock.unschedule(self.accelerate) self.sensorenabled =false self.ids.start_btn.text = "start" def accelerate(self,dt): val=accelerometer.acceleration[:3] if not val==(none,none,none): self.ids.x_val.text="x:" +str(val[0]) self.ids.y_val.text="y:" +str(val[1]) self.ids.z_val.text="z:" +str(val[2]) if self.counter<5: self.x_axis[self.counter] = val[0] self.k=self.x_axis[self.counter]-self.x_axis[self.counter-1] if self.k>8: self.record() self.counter += 1 else: self.counter=0 class meterapp(app): def build(self): return accel() if __name__=="__main__": meterapp().run()
i stuck on more 6 hours. please help
Comments
Post a Comment