I am currently working on an XNA game, however when i command it to play a mp3 file it throws a DRM error when my file is not DRM protected. Can anyone explain to me why this is happening?
public class SoundEffects : GameComponent
{
private Song explosion;
private Song thunder;
public SoundEffects(Game game):base(game)
{
explosion = Game.Content.Load<Song>("explosion");
thunder = Game.Content.Load<Song>("thunder");
}
/*protected override void LoadContent()
{
explosion = Game.Content.Load<Song>("explosion"); // Put the name of your song in instead of "song_title"
thunder = Game.Content.Load<Song>("thunder"); // Put the name of your song in instead of "song_title"
}*/
public void playMusicThunder()
{
MediaPlayer.Play(thunder);
}
public void playMusicExplosion()
{
MediaPlayer.Play(this.explosion);
}
If you attempt to play a song file while the device is connected to the PC via Zune it will throw an exception (DRM). You can either test the game after disconnecting the device or instead of using Zune use the WPconnect tool (which I believe was in the October WPDT update)
Related
I use:
MediaPlayer.Play(song1);
to play a song.
Then I use
MediaPlayer.Play(song2);
to play second song. But Mediaplayer still plays song1. I tried to stop player and play song2 again but it doesn't work. When I swap song1 and song2, it plays only song2.
Edit:
I have this class:
public class SoundHelper
{
public static void PlaySong(Song song)
{
MediaPlayer.Stop();
MediaPlayer.Play(song);
}
public static void StopSong()
{
MediaPlayer.Stop();
}
}
I use:
SoundHelper.PlaySong(Content.Load<Song>("Sounds/Songs/MenuTheme"));
to play song when game starts and it works.
Then I use:
SoundHelper.PlaySong(Content.Load<Song>("Sounds/Songs/Battle"));
to play next song in battle but then MenuTheme is played from beginning.
you have to stop playing current song
if (PlaySong1) {
MediaPlayer.Stop();
MediaPlayer.Play(Song1);
}
else{
MediaPlayer.Stop();
MediaPlayer.Play(Song2);
}
EDIT
you code looks fine, make sure that you call "SoundHelper" only once,
on loading menu or battle.
also try with "try" and "catch" on MediaPlayser.Stop() not sure, but
maybe will throw exception if no song is loaded.
it's better to load songs in your "loadcontent" instead.
song1 = Content.Load<Song>("song1"); song2 = Content.Load<Song>("song2");
also maybe adding MediaPlayer.IsRepeating = true; could be solve.
this is so far all i could remember.
Unfortunately it seems to be a bug in MonoGame. Had that same issue.
With version 3.3 your approach should work.
working on blackberry OS7 9850 device
i am working to Turn on Flash as Light on Blackberry.
i have successfully completed this, but in BBOS6 device 9780 video field is showing; how can i hide that video field?
here is my code
private FlashControl flashControl;
private VideoControl _videoControl;
private Field _videoField;
private ButtonField capture;
private Field videoField;
// Set the displayed title of the screen
public MyScreen(int j) {
try {
Player player = javax.microedition.media.Manager.createPlayer("capture://video?encoding=video/3gpp");
player.realize();
VideoControl videoControl = (VideoControl) player.getControl("VideoControl");
if(videoControl != null)
{
videoField = (Field)videoControl.initDisplayMode( VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" );
try
{
videoControl.setDisplaySize(1, 1);
}
catch(Exception e)
{
}
//videoControl.setDisplaySize( 0 , 0 );
videoControl.setVisible(true);
videoField.setBackground(BackgroundFactory.createSolidBackground(0x000000));
//videoField.
add(videoField);
flashControl = (FlashControl)player.getControl("javax.microedition.amms.control.camera.FlashControl");
setFlashlight(true);
}
player.start();
} catch (Exception e) {
System.out.println(e);
}
}
private void setFlashlight(boolean b) {
if(b == true){
flashControl.setMode(FlashControl.FORCE);
}
else{
flashControl.setMode(FlashControl.OFF);
}
}
is there any solution, like we can push the screen or video field in the background?
There is (at least) one app on BlackBerry World (e.g. One Touch Flashlight) that does this, and it almost certainly accomplishes this task in the following way (instead of using VideoControl and FlashControl):
The app programmatically opens the native Camera app
Using keystroke injection, the app injects touch events to turn on the camera's flash
The app then requests the foreground back (Application#requestForeground()), so that it covers up the Camera app.
When you close the app, it overrides Screen#onClose() and takes the opportunity to inject another Characters.ESCAPE key event, which also closes out the Camera app, which was simply behind the foregrounded "flashlight" app.
You can search Stack Overflow for other examples of opening Camera from your app, using keystroke injection, and requesting your app be brought to the foreground.
References
https://stackoverflow.com/a/6559836/119114
https://stackoverflow.com/a/1298900/119114
http://www.blackberry.com/go/toucheventinjectorsampleapp
I'm trying to play multiple sounds at the same time. However sometimes the sounds just stops playing or never starts at all.
I have an eventhandler that recieves an event when a sound effect should be played:
void HandlePlaySound (object sender, EventArgs e)
{
this.InvokeOnMainThread (()=>{
...
[set url to path]
...
MonoTouch.AVFoundation.AVAudioPlayer player = MonoTouch.AVFoundation.AVAudioPlayer.FromUrl(url);
player.Play();
});
}
This works fine most of the time but when two sounds gets triggered at the same time it's seems like one of them will be killed or both. I must be doing something really wrong here.
Is there a more correct way of playing sounds in an iPhone app. Each sound is supposed to play till end and there could be multiple sounds playing at the same time.
If I were to guess, I'd say that sometimes, the GC comes in and disposes the player that has gone out of scope, causing your random stop behaviour. I found a stable solution being first establishing how many simultaneous audio streams you'd like to able to play, and then enforcing those rules:
// I'd like a maximum of 5 simultaneous audio streams
Queue<AVAudioPlayer> players = new Queue<AVAudioPlayer>(5);
void PlayAudio (string fileName)
{
NSUrl url = NSUrl.FromFilename(fileName);
AVAudioPlayer player = AVAudioPlayer.FromUrl(url);
if (players.Count == 5) {
players.Dequeue().Dispose();
}
players.Enqueue(player);
player.Play();
}
// In my example, I'll select files from my Sounds folder (containing a couple of .wav, a couple of .mp3 and an .aif)
string[] files;
int fileIndex = 0;
string GetNextFileName ()
{
if (files == null)
files = Directory.GetFiles("Sounds");
if (fileIndex == files.Length)
fileIndex = 0;
return files[fileIndex++];
}
partial void OnPlayButtonTapped (NSObject sender)
{
string fileName = GetNextFileName();
PlayAudio(fileName);
}
I load music with the following code in my load content function:
song = Content.Load<Song>("music/game");
MediaPlayer.IsRepeating = false;
MediaPlayer.Play(song);
nothing strange there, but each round in my game is 2 minutes long and should sync up with the music (that is 2 minutes long) but the music ends betweem 2-4s early. This wouldn't be a problem if it was always the same time.
My guess is that it has something to do with load times? any advice?
One thing you could do is move the Content.Load<Song> to Load method and check if it is playing in the update, and if not, play. Eg,
public void LoadContent(ConentManager content)
{
song = content.Load<Song>("music/game");
gameSongStartedPlaying = false; // this variable to hold if you have starting playing this song already
MediaPlayer.IsRepeating = false;
}
public void Update(GameTime gameTime)
{
if(MediaPlayer.State == MediaState.Stopped && !gameSongStartedPlaying)
{
MediaPlayer.Play(song);
gameSongStartedPlaying = true;
}
}
This should start playing the song on the first pass of the Update method rather than in the Loading phase where the song is 'playing' while all resources after Content.Load<Song> are still loading (this would be the reason your song finishes early).
I am developing an application where I want to integrate the SQL database in it. As far my code works fine. I made the application auto-run on startup and I check immediately for SDCard presence. If present I will create the database on SDCard and if not I will create it on device.
The problem is that when the application is auto-run, it will start before the device locates the SDCard, so I am always unable to detect if the SDCard is present.
What listener should I use to know that the device is completely turned on?
SystemListener will do the job. This is how I usually do it:
public class MyApp extends Application implements SystemListener {
public static void main(String[] args){
MyApp app = new MyApp();
if (ApplicationManager.getApplicationManager().inStartup()) {
app.addSystemListener(app);
//wait for powerUp callback
} else {
app.startup();
}
}
public void powerUp() {
removeSystemListener(this);
startup();
}
private void startup(){
//Perform initialization here, most typically show first screen and stuff.
}
// Remaining SystemListener callbacks not shown for brevity
}