Removing Delay in Playing Mp3 Files in Windows Phone 8
-
Dear All, I am developing Windows Phone 8 App in c# and i have followed
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978(v=vs.105).aspx\[^\]
When Playing file, there is 1-3 seconds delay in playing each Mp3 file.
I am looking to remove this delay or play next track (next mp3 file) before reaching just to an end.
Google does not help a lot :(
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
-
Dear All, I am developing Windows Phone 8 App in c# and i have followed
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978(v=vs.105).aspx\[^\]
When Playing file, there is 1-3 seconds delay in playing each Mp3 file.
I am looking to remove this delay or play next track (next mp3 file) before reaching just to an end.
Google does not help a lot :(
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
Hi, this is a code sample that can help you : private HttpWebRequest request; private Mp3MediaStreamSource mss; private string mediaFileLocation = @"http://media.ch9.ms/ch9/755d/4f893d13-fa05-4871-9123-3eadd2f0755d/ EightPlatformAnnouncements.mp3"; public MainPage() { InitializeComponent(); Get = (ApplicationBarIconButton)ApplicationBar.Buttons[0]; Play = (ApplicationBarIconButton)ApplicationBar.Buttons[1]; Pause = (ApplicationBarIconButton)ApplicationBar.Buttons[2]; } private void Get_Click(object sender, EventArgs e) { request = WebRequest.CreateHttp(mediaFileLocation); request.AllowReadStreamBuffering = true; request.BeginGetResponse(new AsyncCallback(RequestCallback), null); } private void RequestCallback(IAsyncResult asyncResult) { HttpWebResponse response = request.EndGetResponse(asyncResult) as HttpWebResponse; Stream s = response.GetResponseStream(); mss = new Mp3MediaStreamSource(s, response.ContentLength); Dispatcher.BeginInvoke(() => { mp3Element.SetSource(mss); Play.IsEnabled = true; Get.IsEnabled = false; }); } private void Play_Click(object sender, EventArgs e) { mp3Element.Play(); Play.IsEnabled = false; Pause.IsEnabled = true; } private void Pause_Click(object sender, EventArgs e) { mp3Element.Pause(); Pause.IsEnabled = false; Play.IsEnabled = true; } Thanks
-
Hi, this is a code sample that can help you : private HttpWebRequest request; private Mp3MediaStreamSource mss; private string mediaFileLocation = @"http://media.ch9.ms/ch9/755d/4f893d13-fa05-4871-9123-3eadd2f0755d/ EightPlatformAnnouncements.mp3"; public MainPage() { InitializeComponent(); Get = (ApplicationBarIconButton)ApplicationBar.Buttons[0]; Play = (ApplicationBarIconButton)ApplicationBar.Buttons[1]; Pause = (ApplicationBarIconButton)ApplicationBar.Buttons[2]; } private void Get_Click(object sender, EventArgs e) { request = WebRequest.CreateHttp(mediaFileLocation); request.AllowReadStreamBuffering = true; request.BeginGetResponse(new AsyncCallback(RequestCallback), null); } private void RequestCallback(IAsyncResult asyncResult) { HttpWebResponse response = request.EndGetResponse(asyncResult) as HttpWebResponse; Stream s = response.GetResponseStream(); mss = new Mp3MediaStreamSource(s, response.ContentLength); Dispatcher.BeginInvoke(() => { mp3Element.SetSource(mss); Play.IsEnabled = true; Get.IsEnabled = false; }); } private void Play_Click(object sender, EventArgs e) { mp3Element.Play(); Play.IsEnabled = false; Pause.IsEnabled = true; } private void Pause_Click(object sender, EventArgs e) { mp3Element.Pause(); Pause.IsEnabled = false; Play.IsEnabled = true; } Thanks
Thanks for the reply, I am storing files locally and I am using BackgroundAudioPlayer instead of Streaming. (I didnt understand mp3Element, object of?)
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
-
Thanks for the reply, I am storing files locally and I am using BackgroundAudioPlayer instead of Streaming. (I didnt understand mp3Element, object of?)
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
Many Thnaks for your nice message. So Having set up the projects, you can then declare an Mp3MediaStreamSource object. The sample app fetches a remote MP3 file by using an HttpWebRequest. When we get the data back, we use it to initialize the Mp3MediaStreamSource and set that as the source for a MediaElement object, which is declared in XAML. Thanks.
-
Many Thnaks for your nice message. So Having set up the projects, you can then declare an Mp3MediaStreamSource object. The sample app fetches a remote MP3 file by using an HttpWebRequest. When we get the data back, we use it to initialize the Mp3MediaStreamSource and set that as the source for a MediaElement object, which is declared in XAML. Thanks.
Thanks for the reply, Can you please help me with Mp3MediaStreamSource class.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
-
Thanks for the reply, Can you please help me with Mp3MediaStreamSource class.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
Unfortunately, the MediaStreamSource class is not well documented. Fortunately, Microsoft has made available a set of helper classes, which you can obtain at https://github.com/loarabia/ManagedMediaHelpers. so in the example that I made before is good way to understand it also. Thanks