I m trying to record a voice using Microphone API in WP7/WP8.
Every thing is working fine when i use it to record a normal voice, but when i use it when a call is answered the application is running well. but when i playback that recorded voice the whole recording is empty, there is no sound at all.
what happened with the microphone in this case?
here is the code which i m using
microphone.BufferDuration = TimeSpan.FromMilliseconds(100);
microphone.Start();
void micro_BufferReady(object sender, EventArgs e)
{
audioBuffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
microphone.GetData(audioBuffer);
currentRecordingStream.Write(audioBuffer, 0, audioBuffer.Length);
}
You can't record a call with the microphone in your app. When a call is activated, the call app on the phone take control of the Microphone and the sound is directed to it, not to your application.
Related
i'm making a simple processing app for a presentation which currently does one thing : it listens to a microphone and emulates a right arrow key down event when it hears sound. I'm using it to synchronize a synth with the OSX finder, so when i play music it iterates through the files of a folder, as if i was pressing repeatedly on the right arrow on my keyboard.
my problem is that the app gets stuck when it hits the last file in a folder. The app needs to be aware of that so it can emulate a left arrow keydown event & a down arrow keydown event to go up a directory and carry on iterating.
I've tried calling applescript from processing to do that, which kind of works, but it's too slow and takes the focus away from the finder, then gives it back, which just looks glitchy (which is important as i'm making this app for a presentation).
I'm guessing i could maybe use a daemon polling which element is currently being selected in the finder, and sending that path to the processing app, and taking action if the path doesn't change after a keypress ; but then i'm not sure how to do that. Can python or bash poll that kind of info from the finder?
thank you!
import processing.sound.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Amplitude amp;
AudioIn in;
Robot robot;
void setup() {
size(1, 1);
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
exit();
}
Sound s = new Sound(this);
s.inputDevice(3);
// select audio device ; if not available will fall back to default input
amp = new Amplitude(this);
in = new AudioIn(this, 0);
in.start();
amp.input(in);
in.play();
// playback of audio input : will larsen if you use computer's mic
}
void draw() {
// println(amp.analyze());
if(amp.analyze()>0.3){
println("go");
// if sound is louder than 0.3 press right key
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);
delay(200);
// prob not the right delay
}
}
I want to write a method in a Windows Phone Application to pause the current playing song and to resume the song if it has paused.
Like a play/pause button.
What is the simplest way to achieve this?
If you want to get it done with the help of the songs stored in the media library the n its easy with the help of MedaPlayer
Use this namespace
using Microsoft.Xna.Framework.Media;
To get all the songs in the media library
MediaLibrary mLibrary = new MediaLibrary();
SongCollection songs= mLibrary.Songs;
To play a specific song
MediaPlayer.Play(songs, int index);
To Pause the mediaplayer
MediaPlayer.Pause();
To continue playing the song
MediaPlayer.Play(songs);
A simple demo as well.
I want to perform some calculations while the phone is in locked screen mode, regardless if the app is on the foreground or the background.
I know that in order to do this, I need to use OnObscured event from App class. However, it is only launched when the app is in the foreground, but not in the background.
So, I would like to know if exist any way to detect the phone state while the App runs the background.
I have thought something that would be crazy, but is to access an API property which is not allowed to use while the phone is in locked screen, and then catch the exception and, with that, get if the phone is active or sleeping.
I am open to hear new ideas.
I figured out a simple thing - maybe it will help you:
I assume that you already disabled Idle Detection to run your calculations in background.
So why not to create the variable in which you hold the state of the App? Since you have to launch first your App, so it goes to foreground and when Obscured is called and IsLocked = true, set the variable. Then you can check it whenever you want:
public MainPage()
{
InitializeComponent();
App.RootFrame.Obscured+=RootFrame_Obscured;
App.RootFrame.Unobscured+=RootFrame_Unobscured;
}
private bool AppIsLocked = false;
private void RootFrame_Unobscured(object sender, EventArgs e)
{
if (AppIsLocked) AppIsLocked = false;
}
private void RootFrame_Obscured(object sender, ObscuredEventArgs e)
{
if (e.IsLocked) AppIsLocked = true;
}
Is this what you searching for Running a Windows Phone Application under the lock screen?
This article describes - how to avoid tombstoning. But you can't do a lot of work under lock screen.
I am making an app for windows phone 8.
On one of the pages of the app, I want to get the co-ordinates of the touch.
I tried searching on net but I got results related to games.
I want to know is it possible to get the position of touch on canvas/or any other component in a simple app.
If yes, plz guide me through it.
Hook up to Tap event of the Control, and use GetPosition of event args.
<Canvas Tap="HandleTap/>
private void HandleTap(object sender, GestureEventArgs e)
{
Point point = e.GetPosition(null);
}
I wish to take a picture on a timer, and process the image at regular intervals, but cannot find anything.
Any help would be appreciated,
Cheers.
There's no way for 3rd party apps to take a picture without the users interaction in this v1 release of the 3rd Party SDK. AR capability is on the radar for the platform team though, so watch this space.
Picture taking capability is currently provided through CameraCaptureTask.
FYI: In Windows Phone OS 7.1 (a.k.a. "Mango"), you can now programmatically capture an image from the camera using the PhotoCamera class. Fire-off a camera capture using the CaptureImage method. When the capture is available, you can access the image (and a thumbnail) from the arguments in the eventhandlers for CaptureImageAvailable and CaptureThumbnailAvailable.
This process is fully described in the following topic:
How to: Create a Base Camera Application for Windows Phone
In that sample, a button is used to trigger the call to CaptureImage, but in a real-world application a timer, like you suggested, would be much more appropriate. (we recommend using the hardware button for user-triggered photos, rather than a UI button. That is described here: How to: Access the Hardware Camera Shutter Button).
Here's the method that actually programmatically triggers the image capture, where cam is the PhotoCamera object:
private void ShutterButton_Click(object sender, RoutedEventArgs e)
{
// Capture a still image. Events are fired as the thumbnail
// and full resolution images become available.
try
{
cam.CaptureImage();
}
catch (Exception ex)
{
this.Dispatcher.BeginInvoke(delegate()
{
// Cannot capture an image until the previous capture has completed.
txtDebug.Text = ex.Message;
});
}
}
Note: PhotoCamera will throw an exception if you try to capture when another capture is in progress. You probably wouldn't have this problem with a timer-based app, but that is why the try/catch is used here. Also, BeginInvoke is used to access the UI thread and display the message in a textBlock on the corresponding page.
Hope that helps. Cheers