title: Play/stop music with classes in kivy
body: <p>I'm trying to execute this:</p>
  
  <pre><code>from kivy.app import App
  from kivy.uix.screenmanager import ScreenManager, Screen
  from kivy.core.audio import SoundLoader,Sound
  from kivy.lang import Builder
  Builder.load_string('''
  &lt;MenuPage&gt;:
      BoxLayout:
          orientation:'vertical'
          Button:
              text:'play'
              on_press:root.plays()
          Button:
              text:'stop'
              on_press:root.stops()
  ''') 
  
  
  class Music(Sound):
      def __init__(self):
          self.sound = SoundLoader.load('/home/hosein/Music/Man.mp3')
  
  
  class MenuPage(Screen):
      def __init__(self):
          self.M = Music()
  
      def plays(self):
          self.M.play()
  
      def stops(self):
          self.M.stop()
  
  music = Music()
  sm = ScreenManager()
  menu = MenuPage(name='menu')
  sm.add_widget(menu)
  
  
  class TestApp(App):
      def build(self):
          return sm
  
  
  
  
  TestApp().run()
  </code></pre>
  
  <p><a href="https://gist.github.com/daryasary/f69e1d0444ae70ff5296" rel="nofollow">https://gist.github.com/daryasary/f69e1d0444ae70ff5296</a></p>
  
  <p>There should be just two buttons to play or stop a song.</p>
  
  <p>But it doesn't work.  What is the solution?</p>
  
  <p>Also, is there any way to make the play and stop buttons into a single button, where the first touch plays the song and the second stops it?</p>