2013-02-07 44 views
1

我只是想運行提供的示例代碼,據我所知,應該工作得很好。有什麼我失蹤或這是模擬器的限制。如何在Blackberry 10 Dev Alpha Simulator中播放SystemSounds?

如果是這樣,是否有任何解決方法?

import bb.cascades 1.0 
// To use the MediaPlayer, we must include 
// the multimedia library. 
import bb.multimedia 1.0 

Page { 
    Container { 
     id: mainContainer 
     layout: StackLayout { 
      orientation: LayoutOrientation.TopToBottom 
     } 
     topPadding: 50.0 
     Label { 
      id: titleLbl 
      text: qsTr("SystemSound and MediaPlayer\n Sample App") 
      multiline: true 
      textStyle.fontSizeValue: 9.0 
      textStyle.fontWeight: FontWeight.Bold 
      textStyle.fontFamily: "Verdana" 
      textStyle.color: Color.DarkBlue 
      textStyle.textAlign: TextAlign.Center 
      horizontalAlignment: HorizontalAlignment.Center 
     } 
     // Part 1 of the sample: Playing system sounds. 
     Container { 
      id: systemSoundsContainer 
      layout: StackLayout { 
       orientation: LayoutOrientation.TopToBottom 
      } 
      topMargin: 100.0 
      horizontalAlignment: HorizontalAlignment.Center 
      DropDown { 
       id: soundSelectorDropdown 
       title: "Sound: " 
       maxWidth: 600.0 
       Option { 
        text: qsTr("Battery Alarm") 
        value: SystemSound.BatteryAlarm 
        selected: true 
       } 
       Option { 
        text: qsTr("Browser Start") 
        value: SystemSound.BrowserStartEvent 
       } 
       Option { 
        text: qsTr("Camera Shutter") 
        value: SystemSound.CameraShutterEvent 
       } 
       Option { 
        text: qsTr("Device Tether") 
        value: SystemSound.DeviceTetherEvent 
       } 
       Option { 
        text: qsTr("General Notification") 
        value: SystemSound.GeneralNotification 
       } 
      } // soundSelectorDropdown 
      Button { 
       id: systemSoundPlayButton 
       text: qsTr("Play Selected System Sound") 
       minWidth: 600.0 
       onClicked: { 
        systemSound.play(); 
       } 
      } // systemSoundPlayButton 
     } // systemSoundsContainer 
     // Part 2 of the sample: Playing custom sound files. 
     Container { 
      id: customSoundsContainer 
      layout: StackLayout { 
       orientation: LayoutOrientation.LeftToRight 
      } 
      topMargin: 100.0 
      Button { 
       id: customSoundPlayButton1 
       text: qsTr("Play Sound 1") 
       layoutProperties: StackLayoutProperties { 
        spaceQuota: 1.0 
       } 
       onClicked: { 
        // Here we could have created a second MediaPlayer object to 
        // use to play our sound, but instead we programmatically 
        // changed the sourceUrl property of the current myPlayer 
        // MediaPlayer object, and re-used it to play our sounds. 
        myPlayer.setSourceUrl("asset:///sounds/Doorbell_001.wav") 
        myPlayer.play() 
       } 
      } // customSoundPlayButton1 
      Button { 
       id: customSoundPlayButton2 
       text: qsTr("Play Sound 2") 
       layoutProperties: StackLayoutProperties { 
        spaceQuota: 1.0 
       } 
       onClicked: { 
        // Same as above, here we also could have created a second 
        // MediaPlayer object to use to play our sound, but instead 
        // we programmatically changed the sourceUrl property of the 
        // current myPlayer MediaPlayer object, and re-used it to 
        // play our sounds. 
        myPlayer.setSourceUrl("asset:///sounds/Doorbell_002.wav") 
        myPlayer.play() 
       } 
      } // customSoundPlayButton2 
     } // customSoundsContainer 
    } // mainContainer 

    // The SystemSound and MediaPlayer objects are attached so 
    // they can be used in our QML code to play sounds. 
    attachedObjects: [   
     SystemSound { 
      id: systemSound 
      sound: soundSelectorDropdown.selectedValue 
     }, 
     MediaPlayer { 
      id: myPlayer 
      // sourceUrl: < Set in the Button control's onClicked event handler. > 
     } 
    ] // Attached objects. 
} 

來源:https://developer.blackberry.com/cascades/documentation/design/audio_video/playing_sounds_code_sample.html

+0

我最終使用基於[[Cowbell]示例項目](https://github.com/blackberry/Cascades-Samples/tree/master/cowbell)的純C++工作,但我仍然對這個問題感到困惑。這個QML解決方案應該工作。 – tcdowney

回答

1

我懷疑是系統聲音實際上是mp3或者.OGG內部文件,其中 「Cowbell sample」 和 「Pull My Beard」 使用.wav文件。這是一個已知的問題,並且已經在Blackberry Developer論壇herehere以及here上討論過,該模擬器沒有正確的編解碼器來播放除.wav文件之外的任何聲音。聲音應該在實際的硬件上正確播放。

相關問題