'[3556] Windows.Media.BackgroundPlayback.exe' has exited with code 1 (0x1) - audio

I am working on a Xamarin UWP app and I am trying to get audio to play in the background. I can get it to play in the foreground just fine with the following code:
private MediaPlayer mediaPlayer;
private string audio;
public void Pause()
{
throw new NotImplementedException();
}
public void Play(string audioUrl)
{z
mediaPlayer = BackgroundMediaPlayer.Current;
if (audio != audioUrl)
{
mediaPlayer.SetUriSource(new Uri(audioUrl));
mediaPlayer.Play();
audio = audioUrl;
}
else
{
mediaPlayer.Play();
}
}
public void Stop()
{
mediaPlayer.Pause();
}
As soon as I add a BackgroundTask to my project I get the titular error:
[3556] Windows.Media.BackgroundPlayback.exe' has exited with code 1 (0x1)
I put everything in the appmanifest correctly. When i remove it from the appmanifest it works just fine in the foreground again.
To be specific the error occurs when I hit the play button in the foreground.

I had to add the BackgroundTasks to a new project

Related

Program closing thread when button pressed Raspberry Pi

I realize there are similar questions here and I have looked at them, I just can't apply the solutions to my own problem.
I am writing an MP3 player for a Pi using visual studio (C#) on a PC, then using Mono on the Pi to run it.
As Mono does not seem to have an MP3 library (happy to be corrected) my workaround is to use a gui interface to control a command line mp3 player (omxplayer).
I have a working test interface which i ssh across to the Pi from my PC to test each time.
The problem is when I hit Button1 to run it, it works fine in that the mp3 plays.
But as soon as I hit button 2 to send the app the "p" key which should pause the program, it just quit out. Ultimately I will have a bunch of buttons sending key presses to control it like next skip stop etc.
I have tested the functionality from a terminal and it works fine.
Any suggestions would be appreciated.
Here is my code.
"Oh", Please don't flame me for making procStartInfo and proc global, I was grasping at straws :)
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
ProcessStartInfo procStartInfo;
System.Diagnostics.Process proc;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "Button Clicked";
procStartInfo = new ProcessStartInfo("omxplayer", "/home/pi/Music/Debug/Mutter.mp3 &");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
private void button3_Click(object sender, EventArgs e)
{
SendKeys.Send("{p}");
}
}
}

Why does my RotateTransition throw errors after it runs for the first time?

Warning: This is my first time using threads and my first time trying out an animation. Please bear with me.
I want to rotate an ImageView. I set up a thread for it:
public class ThreadAnimation extends Thread
{
private ImageView iv;
private RotateTransition rt;
public ThreadAnimation(ImageView iv)
{
this.iv = iv;
}
#Override
public void run()
{
while (true)
{
RotateTransition r = new RotateTransition();
r.setToAngle(360);
r.setCycleCount(1);
r.setDuration(Duration.millis(300));
r.setNode(iv);
r.play();
try
{
sleep(100);
} catch (InterruptedException e)
{
return;
}
}
}
}
I call this inside my controller class, upon pressing a Button.
animation.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle (ActionEvent abschicken)
{
ThreadAnimation thread = null; //ANIMATION PIZZA
if (thread == null)
{
thread = new ThreadAnimation(olivenview);
thread.start();
}
}
});
My ImageView olivenview will rotate just like I wanted it to. However it takes quite a long time until it seems to stop (I can see it because the button triggering it still looks triggered for a while) and when I go ahead to press it a second time afterwards, I get a nonstop error stream with a lot of null pointer exceptions. I am very clueless, can anyone help me out? Is this due to my Thread Setup or does the problem lie somewhere else (in code that I didn't post here)?
I believe you do not need threads for this. Notice the .play() method returns immediately and the animation will run in the background.
That being said, try this.
...
//Create your rotation
final RotateTransition r = new RotateTransition();
r.setToAngle(360);
r.setCycleCount(1);
r.setDuration(Duration.millis(300));
r.setNode(iv);
//When the button is pressed play the rotation. Try experimenting with .playFromStart() instead of .play()
button.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent action) {
r.play();
}
});
...
On an other note I recommend switching to java 8 so that you can use lambda expressions instead of the anonymous class!

Synchronizing an audio file over network in Unet

I have a gameObject "plane" that isn't controlled by the clients. it gets spawned with an audio source that plays a clip when the host clicks a certain button. i would like the sound to be heard by the clients, i tried using rpc but i can't seem to be able to send them.
i keep getting the error: Found no behaviour for incoming [ClientRpc:InvokeRpcRpc_SendSoundIDToServer] on plane (UnityEngine.GameObject), the server and client should have the same NetworkBehaviour instances.
It's been driving me crazy for more than a day, i would really apreciate some help.
Here's my code:
using UnityEngine;
using UnityEngine.Networking;
[RequireComponent(typeof(AudioSource))]
[RequireComponent(typeof(NetworkIdentity))]
public class SpoolUp : NetworkBehaviour
{
private AudioSource source;
public AudioClip[] clips;
public bool start;
void Start()
{
clips = Resources.LoadAll("Audio");
source = GetComponent();
source.playOnAwake = false;
}
public void Spool()
{
start = true;
if (isServer)
PlaySound(0);
}
public void PlaySound(int id)
{
if (id >= 0 && id < clips.Length)
{
RpcPlaySound(id);
}
}
[ClientRpc]
void RpcPlaySound(int id)
{
source.PlayOneShot(clips[id]);
}
PS: I also get the following warning: ClientRpc [ClientRpc:InvokeRpcRpcPlaySound] handler not found [netId=4]

MvvmCross binding iOS Gestures

I'm searching a way how can i bind ios gesture like UILongPressGestureRecognizer to ICommand or MvxCommand in MvvmCross, thanks.
PS : I found an example here but i can't figure out how to do that.
From the example you found and from the current MVVM Cross source I did the following
public static class MvxBehaviourExtensions
{
public static MvxLongPressGestureRecognizerBehaviour LongPress(this UIView view)
{
var toReturn = new MvxLongPressGestureRecognizerBehaviour(view);
return toReturn;
}
}
and
public class MvxLongPressGestureRecognizerBehaviour
: MvxGestureRecognizerBehavior<UILongPressGestureRecognizer>
{
protected override void HandleGesture(UILongPressGestureRecognizer gesture)
{
// Long press recognizer fires continuously. This will ensure we fire
// the command only once. Fire as soon as gesture is recognized as
// a long press.
if (gesture.State == UIGestureRecognizerState.Began)
{
FireCommand();
}
}
public MvxLongPressGestureRecognizerBehaviour(UIView target)
{
var lp = new UILongPressGestureRecognizer(HandleGesture);
AddGestureRecognizer(target, lp);
}
}
and to bind
set.Bind(this.LongPress()).For(lp => lp.Command).To(c => c.DoTheStuffCommand);

JME Push Registry Alarm

My midlet is meant to register an alarm but when I test it on my Nokia 2680s-2 this is what happens;
When I exit the midlet by pressing the soft key that has the exit command the midlet does not wake up at the required time meaning that the alarm time was not registered in the push registry. However when I exit the midlet by pressing the power off/on key, the phone prompts to respond as to whether you want the midlet to auto start (SecurityException) when you accept, the midlet alarm time is registered and it auto starts.
My commandAction listener handles the exit command as follows:
if (command == myExit)
{
notifyDestroyed();
}
The alarm registration is handled in the destroyApp() as below:
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
try
{
setMidletWakeupTime(someTimeValueAsLong);
}
catch(ClassNotFoundException cnfe)
{
}
catch(ConnectionNotFoundException cnfe)
{
}
catch(SecurityException se)
{
}
}
The setMidletWakeupTime function code is as follows:
public void setMidletWakeupTime(long wakeupTime)
throws ClassNotFoundException, ConnectionNotFoundException,
SecurityException
{
String className = this.getClass().getName();
PushRegistry.registerAlarm(className, wakeupTime);
}

Resources