Alarm with song from Music store - windows-phone-8

I am new to Windows Phone 8 platform and I want to develop an application for showing alarm.
In that I need to put an option for selecting the alarm sound from music store. Here I want to know how to set an alarm with song from music store.

Try this snippet out.
Alarm alarm = new Alarm(name);
alarm.Content = contentTextBox.Text;
alarm.Sound = new Uri("/Ringtones/Ring01.wma", UriKind.Relative);
alarm.BeginTime = beginTime;
alarm.ExpirationTime = expirationTime;
alarm.RecurrenceType = recurrence;
ScheduledActionService.Add(alarm);
For more take a look over here

Use WebClient to download the alarm sound from server
WebClient client = new WebClient();
Uri uri = new Uri(songUrl);
client.OpenReadCompleted += new OpenReadCompletedEventHandler(OpenReadCallback2);
client.OpenReadAsync(uri);
In the OpenReadCallback2
private void OpenReadCallback2(object sender, OpenReadCompletedEventArgs e)
{
byte[] buffer = new byte[e.Result.Length];
e.Result.Read(buffer, 0, buffer.Length);
using (var fs = File.Create("file.mp3"))
{
fs.Write(buffer, 0, buffer.Length);
}
Save stream in to a file named "file.mp3"
Now create your alarm
Alarm objAlarm = ScheduledActionService.Find("samplealarm123") as Alarm;
if (objAlarm != null)
ScheduledActionService.Remove("samplealarm123");
objAlarm = new Alarm("samplealarm123");
objAlarm.Content = "sample alarm";
objAlarm.Sound = new Uri("/file.mp3", UriKind.Relative); ;
objAlarm.BeginTime = dt;// datetime.now.addminutes(1);
objAlarm.ExpirationTime = dt.AddMinutes(1);
ScheduledActionService.Add(objAlarm);
This will play the song downloaded from server as Alarm tune.

Related

Play two videos simultaneously with sync in AS3

I am busy with a project where two videos have to play on top of each other.
Like the one in the following site, http://kindnessday.sg/home#/kindness/home
Because of the large filesize I cannot embed the videos in the swf. It will become too large. Therefore the video's must be loaded thro' webstream link. But First video plays before the second video and causing the videos unsynced.
Is there a way to play both video at the same time?
var stream = 'http://mydomain/clip1.mp4'
var stream1 = 'https://mydomain/clip2.mp4'
var http_stream:URLStream = null
var http_stream1:URLStream = null
var video:Video = new Video() // the video is used only to ensure that stream is playing
var video1:Video = new Video() // the video is used only to ensure that stream is playing
addChild(video1)
addChild(video)
var nc:NetConnection = new NetConnection()
nc.connect(null)
var ns:NetStream = new NetStream(nc)
ns.client = new Object()
ns.client.onMetaData = function(e){}
ns.play(null)
var ns1:NetStream = new NetStream(nc)
ns1.client = new Object()
ns1.client.onMetaData = function(e){}
ns1.play(null)
video.attachNetStream(ns)
video1.attachNetStream(ns1)
http_stream = new URLStream();
http_stream.addEventListener(ProgressEvent.PROGRESS, on_Progress)
http_stream.load(new URLRequest(stream))
http_stream1 = new URLStream();
//http_stream1.addEventListener(ProgressEvent.PROGRESS, on_Progress1)
http_stream1.load(new URLRequest(stream1))
function on_Progress(e:ProgressEvent):void {
var b:ByteArray = new ByteArray()
http_stream.readBytes(b, 0, http_stream.bytesAvailable)
ns.appendBytes(b)
var b1:ByteArray = new ByteArray()
http_stream1.readBytes(b1, 0, http_stream1.bytesAvailable)
ns1.appendBytes(b1)
if (ns.appendBytes(b)==ns1.appendBytes(b1)){
ns.play(stream);
ns1.play(stream1);
}
}
why not not check how much of each video has loaded and when you have enough amount (you decide) then you can run some function to play both netstreams...
var min_amount : int = 500000; //for 500 kb minimum
var check_if_ready : Boolean = true;
Also on progressEvent function of loading (URLloader or URLstream???)..
if ( check_if_ready == true )
{
if( myA_NetStream.bytesLoaded >= min_amount && myB_NetStream.bytesLoaded >= min_amount )
{
myA_NetStream.play(); myB_NetStream.play();
//reset since not needed on further progressEvents during this load
check_if_ready = false;
}
}
}
This should only play when both videos have loaded x-amount of bytes. Therefore you can be sure none starts before another)
For better synchronization control you should get into handling bytes in Flash/AS3 and using the AppendBytes method because then you can control playback on a frame-by-frame basis for both NetStreams.

Cannot play correctly ogg music on WP8 after decoding it with NVorbis and play with Sharpdx and XNA SoundEffect

I try to play a ogg music file using NVorbis to decode it, and sharpdx + XNA SoundEffect
Vorbis decoder seems to work as the informations (channels, duration, SampleRate) are fine.
then I use Sharpdx to create the wave Stream that will be used to create the SoundEffect.
But when I try to play it, I can recognise my sound, but there also a lot of "noise" in background and the music is distorted.
I don't know what to do... thanks for help!
here is my code:
string _audioPath = "music/2test.ogg";
NVorbis.Ogg.ContainerReader oggReader = new NVorbis.Ogg.ContainerReader(_audioPath);
using (var vorbis = new NVorbis.VorbisReader(oggReader))
{
int channels = vorbis.Channels;
int sampleRate = vorbis.SampleRate;
var duration = vorbis.TotalTime;
var buffer = new float[vorbis.TotalSamples];
int count;
count = vorbis.ReadSamples(buffer, 0, buffer.Length);
//var byteArray = new byte[buffer.Length * 4];
// Buffer.BlockCopy(buffer, 0, byteArray, 0, byteArray.Length);
MemoryStream stream = new MemoryStream();
// BinaryWriter writer = new BinaryWriter(stream);
SharpDX.Multimedia.WaveFormat wf = new SharpDX.Multimedia.WaveFormat(sampleRate, channels);
SharpDX.Multimedia.WavWriter w = new SharpDX.Multimedia.WavWriter(stream);
w.Begin(wf);
w.AppendData(buffer);
w.End();
stream.Position = 0;
_SoundEffect = SoundEffect.FromStream(stream);
_SoundEffectInstance = _SoundEffect.CreateInstance();
_SoundEffectInstance.Play();
}

How to download images from image urls in windows phone8 using asynctask

I'm having 10 image urls. I want to download those images and htmls to local folder and replace the image paths in corresponding image source of htmls. How to download 10 images from urls. below code for single image download.
var webClient = new WebClient();
webClient.OpenReadCompleted += WebClientOpenReadCompleted;
webClient.OpenReadAsync(new Uri(webimages["image url"], UriKind.Absolute));
void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
const string tempJpeg = "TempJPEG";
var streamResourceInfo = new StreamResourceInfo(e.Result, null);
var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
if (userStoreForApplication.FileExists(tempJpeg))
{
// userStoreForApplication.DeleteFile(tempJpeg);
MessageBox.Show("Image Already Exists");
}
var isolatedStorageFileStream = userStoreForApplication.CreateFile(tempJpeg);
var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None };
bitmapImage.SetSource(streamResourceInfo.Stream);
var writeableBitmap = new WriteableBitmap(bitmapImage);
writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
isolatedStorageFileStream.Close();
isolatedStorageFileStream = userStoreForApplication.OpenFile(tempJpeg, FileMode.Open, FileAccess.Read);
// Save the image to the camera roll or saved pictures album.
var mediaLibrary = new MediaLibrary();
// Save the image to the saved pictures album.
mediaLibrary.SavePicture(string.Format("SavedPicture{0}.jpg", DateTime.Now), isolatedStorageFileStream);
isolatedStorageFileStream.Close();
}

WriteableBitmapRenderer.RenderAsync() ArgumentException "Value does not fall within the expected range"

I'm developing a WP8 app using Nokia Imaging SDK.
I'm trying to add filter effect to an image and render it into a WriteableBitmap.
Here is my code:
private async void PhotoChosen(object sender, PhotoResult photoResult)
{
if (photoResult != null)
{
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(photoResult.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
StreamImageSource source = new StreamImageSource(photoResult.ChosenPhoto);
var effects = new FilterEffect(source);
effects.Filters = new IFilter[] { new SketchFilter() };
var renderer = new WriteableBitmapRenderer(effects, wb);
await renderer.RenderAsync();
}
}
All is going fine, but when this line is processing:
await renderer.RenderAsync();
This ArgumentException is thrown:
Value does not fall within the expected range
I think I've made a mistake creating the IImageProvider effects or the WriteableBitmap wb
Does anyone got this problem and found an issue ?
Thanks :)
You need to set the stream position before setting it as source for StreamImageSource.
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(photoResult.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
photoResult.ChosenPhoto.Position = 0;
StreamImageSource source = new StreamImageSource(photoResult.ChosenPhoto);
You need to do this because you have called bitmap.SetSource(photoResult.ChosenPhoto). That means that the stream has already been read once, therefore it's position is at the very end of the stream. When StreamImageSource tries to read it, it is already at the end, thus "Value does not fall within the expected range."

Text stops showing unless not playing

So i finally got my flash application to work and have it running on a website but after a while the dynamic text stops showing up in the fields. The file is set to loop every 5 seconds and it is supposed to update to show the staff on air and what is currently playing. Link to the website is http://mischieffm.com/
var xmlData:XML = new XML();
var header:URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
var theURL_ur:URLRequest = new URLRequest ("/stream/shout.xml?rnd=" + Math.random());
var loader_ul:URLLoader = new URLLoader(theURL_ur);
loader_ul.addEventListener("complete", fileLoaded);
function fileLoaded(e:Event):void
{
xmlData = XML(loader_ul.data);
show_txt.text = xmlData.SERVERTITLE;
song_txt.text = xmlData.SONGTITLE;
}
This is all done in cs6 flash pro and actionscript 3
Try this:
function fileLoaded(e:Event):void
{
loader_ul.removeEventListener("complete", fileLoaded);
xmlData = new XML(loader_ul.data);
if (xmlData.SONGTITLE && xmlData.SERVERTITLE)
{
show_txt.text = xmlData.SERVERTITLE;
song_txt.text = xmlData.SONGTITLE;
}
else
{
show_txt.text = "Untitled artist";
song_txt.text = "Untitled song";
}
}
Note: In order to prevent memory leaks, always call removeEventListener("someEvent", someMethod); after your event gets dispatched. There are some exclusions, but generally you should do it all the time.