乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Python實(shí)例講解- 定時(shí)播放

       londonKu 2012-03-30

      自己寫(xiě)的鬧鐘, 只可以播放wav格式的音頻。

       

      Python代碼  收藏代碼
      1. import time  
      2. import sys  
      3.   
      4. soundFile = 'sound.wav'  
      5. not_executed = 1  
      6.   
      7. def soundStart():  
      8.     if sys.platform[:5] == 'linux':  
      9.         import os  
      10.         os.popen2('aplay -q' + soundFile)  
      11.     else:  
      12.         import winsound  
      13.         winsound.PlaySound(soundFile, winsound.SND_FILENAME)  
      14.           
      15. while(not_executed):  
      16.     dt = list(time.localtime())  
      17.     hour = dt[3]  
      18.     minute = dt[4]  
      19.     if hour == 17 and minute == 38# 下午5點(diǎn)33分的時(shí)候開(kāi)始提示  
      20.         soundStart()  
      21.         not_executed = 0  
       

       

      winsound 模塊提供訪問(wèn)由 Windows 平臺(tái)提供的基本的聲音播放設(shè)備。它包含函數(shù)和數(shù)個(gè)常量。

       

      Beep(frequency, duration)

          蜂鳴PC的喇叭。 frequency 參數(shù)指定聲音的頻率,以赫茲,并且必須是在 37 到 32,767

      的范圍之中。duration 參數(shù)指定聲音應(yīng)該持續(xù)的毫秒數(shù)。如果系統(tǒng)不能蜂鳴喇叭,掛起 RuntimeError。注意:Windows 95 和 98下,Windows Beep() 函數(shù)存在但是無(wú)效的(它忽略它的參數(shù))。這種情況下Python通過(guò)直接的端口操作模擬它(2.1版本中增加的)。不知道是否在所有的系統(tǒng)上都工作。 1.6版本中的新特性。

       

      PlaySound(sound, flags)

          從平臺(tái) API 中調(diào)用 PlaySound() 函數(shù)。sound 參數(shù)必須是一個(gè)文件名,音頻數(shù)據(jù)作為字符串,或?yàn)?None。它的解釋依賴(lài)于 flags 的值,該值可以是一個(gè)位方式或下面描述的變量的組合。如果系統(tǒng)顯示一個(gè)錯(cuò)誤,掛起 RuntimeError 。

       

      MessageBeep([type=MB_OK])

          從平臺(tái) API 中調(diào)用 MessageBeep() 函數(shù)。播放一個(gè)在注冊(cè)表中指定的聲音。type 參數(shù)指定播放哪一個(gè)聲音;可能的值是 -1,MB_ICONASTERISK,MB_ICONEXCLAMATION,MB_ICONHAND,MB_ICONQUESTION,和 MB_OK,所有的描述如下。值 -1 產(chǎn)生一個(gè)``簡(jiǎn)單的蜂鳴'';換句話說(shuō)這是如果聲音不能被播放的后備計(jì)劃。2.3版本中的新特性。

       

      SND_FILENAME

          sound 參數(shù)是一個(gè) WAV 文件的名稱(chēng)。不使用 SND_ALIAS。

       

      SND_ALIAS

          sound 參數(shù)是注冊(cè)表中一個(gè)聲音組合的名稱(chēng)。如果注冊(cè)表沒(méi)有包含這樣的名稱(chēng),播放系統(tǒng)缺省的聲音除非 SND_NODEFAULT 也被指定。如果沒(méi)有缺省的聲音被注冊(cè),掛起 RuntimeError。不使用 SND_FILENAME。

          所有的 Win32 系統(tǒng)至少支持下列,大多數(shù)系統(tǒng)支持的更多:

          PlaySound() 名稱(chēng)         對(duì)應(yīng)的控制面板聲音名稱(chēng)

          'SystemAsterisk'                      Asterisk

          'SystemExclamation'              Exclamation

          'SystemExit'                              Exit Windows

          'SystemHand'                      Critical Stop

          'SystemQuestion'              Question

          例子:

       

       

      Python代碼  收藏代碼
      1. import winsound  
      2.   
      3. # Play Windows exit sound.  
      4. winsound.PlaySound("SystemExit", winsound.SND_ALIAS)  
      5.   
      6. # Probably play Windows default sound, if any is registered (because  
      7. # "*" probably isn't the registered name of any sound).  
      8. winsound.PlaySound("*", winsound.SND_ALIAS)  
       

       

      SND_LOOP

          重復(fù)地播放聲音。SND_ASYNC標(biāo)識(shí)也必須被用來(lái)避免堵塞。不能用 SND_MEMORY。

       

      SND_MEMORY

          提供給PlaySound()的 sound 參數(shù)是一個(gè) WAV 文件的內(nèi)存映像(memory image),作為一個(gè)字符串。

          注意:這個(gè)模塊不支持從內(nèi)存映像中異步播放,因此這個(gè)標(biāo)識(shí)和 SND_ASYNC 的組合將掛起 RuntimeError。

       

      SND_PURGE

          停止播放所有指定聲音的實(shí)例。

       

      SND_ASYNC

          立即返回,允許聲音異步播放。

       

      SND_NODEFAULT

          不過(guò)指定的聲音沒(méi)有找到,不播放系統(tǒng)缺省的聲音。

       

      SND_NOSTOP

          不中斷當(dāng)前播放的聲音。

       

      SND_NOWAIT

          如果聲音驅(qū)動(dòng)忙立即返回。

       

      MB_ICONASTERISK

          播放 SystemDefault 聲音。

       

      MB_ICONEXCLAMATION

          播放 SystemExclamation 聲音。

       

      MB_ICONHAND

          播放 SystemHand 聲音。

       

      MB_ICONQUESTION

          播放 SystemQuestion 聲音。


      MB_OK

          播放 SystemDefault 聲音。

       

       

       

      實(shí)例一

       

      Python代碼  收藏代碼
      1. import wx  
      2. from wx.lib.filebrowsebutton import FileBrowseButton  
      3.   
      4. class MyFrame(wx.Frame):  
      5.     def __init__(self):  
      6.         wx.Frame.__init__(selfNone, title="wx.Sound",size=(500,100))  
      7.         p = wx.Panel(self)  
      8.   
      9.         self.fbb = FileBrowseButton(p,labelText="Select WAV file:",fileMask="*.wav")  
      10.         btn = wx.Button(p, -1"Play")  
      11.         self.Bind(wx.EVT_BUTTON, self.OnPlaySound, btn)  
      12.           
      13.         sizer = wx.BoxSizer(wx.HORIZONTAL)  
      14.         sizer.Add(self.fbb, 1, wx.ALIGN_CENTER_VERTICAL)  
      15.         sizer.Add(btn, 0, wx.ALIGN_CENTER_VERTICAL)  
      16.         border = wx.BoxSizer(wx.VERTICAL)  
      17.         border.Add(sizer, 0, wx.EXPAND|wx.ALL, 15)  
      18.         p.SetSizer(border)  
      19.   
      20.   
      21.     def OnPlaySound(self, evt):  
      22.         filename = self.fbb.GetValue()  
      23.         self.sound = wx.Sound(filename)  
      24.         if self.sound.IsOk():  
      25.             self.sound.Play(wx.SOUND_ASYNC)  
      26.         else:  
      27.             wx.MessageBox("Invalid sound file""Error")  
      28.       
      29.   
      30. app = wx.PySimpleApp()  
      31. frm = MyFrame()  
      32. frm.Show()  
      33. app.MainLoop()  
       

       

      實(shí)例二

       

      Python代碼  收藏代碼
      1. import wx  
      2. import wx.media  
      3. import os  
      4.   
      5. class Panel1(wx.Panel):  
      6.     def __init__(self, parent, id):  
      7.         #self.log = log  
      8.         wx.Panel.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN)  
      9.   
      10.         # Create some controls  
      11.         try:  
      12.             self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)  
      13.         except NotImplementedError:  
      14.             self.Destroy()  
      15.             raise  
      16.   
      17.         loadButton = wx.Button(self, -1"Load File")  
      18.         self.Bind(wx.EVT_BUTTON, self.onLoadFile, loadButton)  
      19.           
      20.         playButton = wx.Button(self, -1"Play")  
      21.         self.Bind(wx.EVT_BUTTON, self.onPlay, playButton)  
      22.           
      23.         pauseButton = wx.Button(self, -1"Pause")  
      24.         self.Bind(wx.EVT_BUTTON, self.onPause, pauseButton)  
      25.           
      26.         stopButton = wx.Button(self, -1"Stop")  
      27.         self.Bind(wx.EVT_BUTTON, self.onStop, stopButton)  
      28.   
      29.         slider = wx.Slider(self, -1000, size=wx.Size(300, -1))  
      30.         self.slider = slider  
      31.         self.Bind(wx.EVT_SLIDER, self.onSeek, slider)  
      32.           
      33.         self.st_file = wx.StaticText(self, -1".mid .mp3 .wav .au .avi .mpg", size=(200,-1))  
      34.         self.st_size = wx.StaticText(self, -1, size=(100,-1))  
      35.         self.st_len  = wx.StaticText(self, -1, size=(100,-1))  
      36.         self.st_pos  = wx.StaticText(self, -1, size=(100,-1))  
      37.           
      38.         # setup the button/label layout using a sizer  
      39.         sizer = wx.GridBagSizer(5,5)  
      40.         sizer.Add(loadButton, (1,1))  
      41.         sizer.Add(playButton, (2,1))  
      42.         sizer.Add(pauseButton, (3,1))  
      43.         sizer.Add(stopButton, (4,1))  
      44.         sizer.Add(self.st_file, (12))  
      45.         sizer.Add(self.st_size, (22))  
      46.         sizer.Add(self.st_len,  (32))  
      47.         sizer.Add(self.st_pos,  (42))  
      48.         sizer.Add(self.mc, (5,1), span=(5,1))  # for .avi .mpg video files  
      49.         self.SetSizer(sizer)  
      50.   
      51.         self.timer = wx.Timer(self)  
      52.         self.Bind(wx.EVT_TIMER, self.onTimer)  
      53.         self.timer.Start(100)  
      54.           
      55.     def onLoadFile(self, evt):  
      56.         dlg = wx.FileDialog(self, message="Choose a media file",  
      57.                             defaultDir=os.getcwd(), defaultFile="",  
      58.                             style=wx.OPEN | wx.CHANGE_DIR )  
      59.         if dlg.ShowModal() == wx.ID_OK:  
      60.             path = dlg.GetPath()  
      61.             self.doLoadFile(path)  
      62.         dlg.Destroy()  
      63.           
      64.     def doLoadFile(self, path):  
      65.         if not self.mc.Load(path):  
      66.             wx.MessageBox("Unable to load %s: Unsupported format?" % path, "ERROR", wx.ICON_ERROR | wx.OK)  
      67.         else:  
      68.             folder, filename = os.path.split(path)  
      69.             self.st_file.SetLabel('%s' % filename)  
      70.             self.mc.SetBestFittingSize()  
      71.             self.GetSizer().Layout()  
      72.             self.slider.SetRange(0self.mc.Length())  
      73.             self.mc.Play()  
      74.           
      75.     def onPlay(self, evt):  
      76.         self.mc.Play()  
      77.       
      78.     def onPause(self, evt):  
      79.         self.mc.Pause()  
      80.       
      81.     def onStop(self, evt):  
      82.         self.mc.Stop()  
      83.       
      84.     def onSeek(self, evt):  
      85.         offset = self.slider.GetValue()  
      86.         self.mc.Seek(offset)  
      87.   
      88.     def onTimer(self, evt):  
      89.         offset = self.mc.Tell()  
      90.         self.slider.SetValue(offset)  
      91.         self.st_size.SetLabel('size: %s ms' % self.mc.Length())  
      92.         self.st_len.SetLabel('( %d seconds )' % (self.mc.Length()/1000))  
      93.         self.st_pos.SetLabel('position: %d ms' % offset)  
      94.   
      95.   
      96. app = wx.PySimpleApp()  
      97. # create a window/frame, no parent, -1 is default ID  
      98. frame = wx.Frame(None, -1"play audio and video files", size = (320350))  
      99. # call the derived class  
      100. Panel1(frame, -1)  
      101. frame.Show(1)  
      102. app.MainLoop()  

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶(hù) 評(píng)論公約

        類(lèi)似文章 更多