Click here to Skip to main content
15,889,695 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've seen this type of question but none of those goes to my requirements. I've got various types of ringtone in my server. now i need to know how to read those audio file and save into my windows phone 8 directory. Please help me; I'm waiting for your valuable suggestion. Thanks in Advance
Posted
Comments
[no name] 25-May-14 9:31am    
What have you tried and what is the problem with what you have tried? Did you see http://www.geekchamp.com/tips/save-an-audio-file-as-a-ringtone-in-windows-phone-8?
suzand 26-May-14 8:55am    
StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri("https://dl.dropboxusercontent.com/u/65265347/dog38catsi_a2yn44rm.mp3", UriKind.Absolute)); THIS LINE OF CODE GENERATE EXCEPTION "An exception of type 'System.ArgumentException' occurred in System.Windows.ni.dll but was not handled in user code"
suzand 26-May-14 8:54am    
StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri("https://dl.dropboxusercontent.com/u/65265347/dog38catsi_a2yn44rm.mp3", UriKind.Absolute)); THIS LINE OF CODE GENERATE EXCEPTION "An exception of type 'System.ArgumentException' occurred in System.Windows.ni.dll but was not handled in user code"

1 solution

////// For Download and save
private void addButton_Click(object sender, RoutedEventArgs e)
{

WebClient webClient = new WebClient();
webClient.OpenReadAsync(new Uri("https://dl.dropboxusercontent.com/u/65265347/dog38catsi_a2yn44rm.mp3", UriKind.RelativeOrAbsolute));
webClient.OpenReadCompleted+=webClient_OpenReadCompleted;

}



void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
string fileName = "createmytone.mp3";
Debug.WriteLine(e.Result);
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(fileName))
{
myIsolatedStorage.DeleteFile(fileName);
}

using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(fileName, FileMode.Create, myIsolatedStorage))
{
using (BinaryWriter writer = new BinaryWriter(fileStream))
{
Stream resourceStream = e.Result as Stream;
//streamResourceInfo.Stream;
long length = resourceStream.Length;
byte[] buffer = new byte[32];
int readCount = 0;
using (BinaryReader reader = new BinaryReader(resourceStream))
{
// read file in chunks in order to reduce memory consumption and increase performance
while (readCount < length)
{
int actual = reader.Read(buffer, 0, buffer.Length);
readCount += actual;
writer.Write(buffer, 0, actual);
}
}
}
}
}
}
//// Set as Ringtone
SaveRingtoneTask saveRingtoneTask = null;
private void setRingtoneButton_Click(object sender, RoutedEventArgs e)
{
try
{
string isoStorePath = string.Concat("isostore:/", "createmytone.mp3");
saveRingtoneTask.Source = new Uri(isoStorePath);
saveRingtoneTask.DisplayName = "My Ringtone...";
saveRingtoneTask.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900