Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Removing Delay in Playing Mp3 Files in Windows Phone 8

Removing Delay in Playing Mp3 Files in Windows Phone 8

Scheduled Pinned Locked Moved Mobile
csharpdatabasevisual-studiocomhelp
6 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abdul Rahman Hamidy
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • A Abdul Rahman Hamidy

      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

      H Offline
      H Offline
      Hadrich Mohamed
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • H Hadrich Mohamed

        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

        A Offline
        A Offline
        Abdul Rahman Hamidy
        wrote on last edited by
        #3

        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

        H 1 Reply Last reply
        0
        • A Abdul Rahman Hamidy

          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

          H Offline
          H Offline
          Hadrich Mohamed
          wrote on last edited by
          #4

          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.

          A 1 Reply Last reply
          0
          • H Hadrich Mohamed

            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.

            A Offline
            A Offline
            Abdul Rahman Hamidy
            wrote on last edited by
            #5

            Thanks for the reply, Can you please help me with Mp3MediaStreamSource class.

            Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

            H 1 Reply Last reply
            0
            • A Abdul Rahman Hamidy

              Thanks for the reply, Can you please help me with Mp3MediaStreamSource class.

              Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

              H Offline
              H Offline
              Hadrich Mohamed
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups