In Windows Phone 7.5, we can save a piece of music as a ringtone in the program. However, there are some restrictions on the storage of music files:
1. The file must be in MP3 or WMA format.
2. The length of the ringtone file must be less than 40 seconds.
3. No copyright restrictions on ringtone files
4. The ringtone file size must be smaller than 1 MB.
In actual processing, the file we want to save as a ringtone is likely to be a complete song with a size greater than 1 MB. So how can we save the song climax as a ringtone? For example, "on the beach" definitely wants to save what is "on the waves, on the waves.
According to some of my non-professional understandings: A Song generally has two reincarts, And the climax usually appears at the end of each cycle, that is, between 1/4 and 1/3 of a song. Then we can save that part as another file.
The Demo below demonstrates how to save a part of a local song as a ringtone.
First, let's take a look at the intercepted code:
private void SaveIntoIso ()
{
Stream stream = App.GetResourceStream (new Uri ("mangoRingtones; component / beat_it.mp3", UriKind.Relative)). Stream;
// read some of them
stream.Seek (stream.Length / 4, 0);
byte [] buffer = new byte [stream.Length / 3-stream.Length / 4];
stream.Read (buffer, 0, buffer.Length);
// save into isostore
using (var isostore = IsolatedStorageFile.GetUserStoreForApplication ())
{
using (var inp = isostore.OpenFile (fileName, FileMode.OpenOrCreate, FileAccess.Write))
{
inp.Write (buffer, 0, buffer.Length);
}
}
stream.Close ();
stream.Dispose ();
}
Read the stream from the local and save part of it as another file.
Then let's take a look at how we can save audio files as phone ringtones in Windows Phone.
SaveRingtoneTask task = new SaveRingtoneTask ();
task.DisplayName = "beat it";
task.Source = new Uri (@ "isostore: /" + fileName);
task.Completed + = new EventHandler <TaskEventArgs> (task_Completed);
task.Show ();
Note that referencing files in independent storage space can use the new Uri (@ "isostore: /" + fileName);
You can find the source code of this article here.