none
AudioPlayback Agent problem on WP8 Emulator

    Question

  • Hello, I'm having a problem running on AudioPlayback Agent in WP8 Emulator
    The next execution in wp7 works and does not work in WP8.

            // A playlist made up of AudioTrack items.

            private static List<AudioTrack> _playList = new List<AudioTrack>
            {

                new AudioTrack(new Uri("http://65.60.52.122:8700/;stream.mp3", UriKind.Absolute), 
                                "Ringtone 3", 
                                "Windows Phone", 
                                "Windows Phone Ringtones", 
                                new Uri("shared/media/Ring03.jpg", UriKind.Relative)),
            };

    Tuesday, February 12, 2013 12:15 AM

All replies

  • Can you explain more about what you're asking, and post more code?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, February 12, 2013 7:16 PM
  • development was made based on the code from the link below, but instead of running mp3 file, run a stream of audio.

    works great on wp7, but not in WP8

    http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978(v=vs.105).aspx

    /* 
        Copyright (c) 2011 Microsoft Corporation.  All rights reserved.
        Use of this sample source code is subject to the terms of the Microsoft license 
        agreement under which you licensed this sample source code and is provided AS-IS.
        If you did not accept the terms of the license agreement, you are not authorized 
        to use this sample source code.  For the terms of the license, please see the 
        license agreement between you and Microsoft.
      
        To see all Code Samples for Windows Phone, visit http://go.microsoft.com/fwlink/?LinkID=219604 
      
    */
    using System;
    using System.Windows;
    using Microsoft.Phone.BackgroundAudio;
    using System.Collections.Generic;
    
    namespace MyAudioPlaybackAgent
    {
        public class AudioPlayer : AudioPlayerAgent
        {
            private static volatile bool _classInitialized;
    
            // What's the current track?
            static int currentTrackNumber = 0;
    
            // A playlist made up of AudioTrack items.
            private static List<AudioTrack> _playList = new List<AudioTrack>
            {
    
                new AudioTrack(new Uri("http://65.60.52.122:8700/;stream.mp3", UriKind.Absolute), 
                                "Ringtone 3", 
                                "Windows Phone", 
                                "Windows Phone Ringtones", 
                                new Uri("shared/media/Ring03.jpg", UriKind.Relative)),
            };
    
    
            /// <remarks>
            /// AudioPlayer instances can share the same process. 
            /// Static fields can be used to share state between AudioPlayer instances
            /// or to communicate with the Audio Streaming agent.
            /// </remarks>
            public AudioPlayer()
            {
                if (!_classInitialized)
                {
                    _classInitialized = true;
                    // Subscribe to the managed exception handler
                    Deployment.Current.Dispatcher.BeginInvoke(delegate
                    {
                        Application.Current.UnhandledException += AudioPlayer_UnhandledException;
                    });
                }
            }
    
            /// Code to execute on Unhandled Exceptions
            private void AudioPlayer_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    // An unhandled exception has occurred; break into the debugger
                    System.Diagnostics.Debugger.Break();
                }
            }
    
    
            /// <summary>
            /// Increments the currentTrackNumber and plays the correpsonding track.
            /// </summary>
            /// <param name="player">The BackgroundAudioPlayer</param>
            private void PlayNextTrack(BackgroundAudioPlayer player)
            {
                if (++currentTrackNumber >= _playList.Count)
                {
                    currentTrackNumber = 0;
                }
    
                PlayTrack(player);
            }
    
    
            /// <summary>
            /// Decrements the currentTrackNumber and plays the correpsonding track.
            /// </summary>
            /// <param name="player">The BackgroundAudioPlayer</param>
            private void PlayPreviousTrack(BackgroundAudioPlayer player)
            {
                if (--currentTrackNumber < 0)
                {
                    currentTrackNumber = _playList.Count - 1;
                }
    
                PlayTrack(player);
            }
    
    
            /// <summary>
            /// Plays the track in our playlist at the currentTrackNumber position.
            /// </summary>
            /// <param name="player">The BackgroundAudioPlayer</param>
            private void PlayTrack(BackgroundAudioPlayer player)
            {
                if (PlayState.Paused == player.PlayerState)
                {
                    // If we're paused, we already have 
                    // the track set, so just resume playing.
                    player.Play();
                }
                else
                {
                    // Set which track to play. When the TrackReady state is received 
                    // in the OnPlayStateChanged handler, call player.Play().
                    player.Track = _playList[currentTrackNumber];
                }
    
            }
    
    
            /// <summary>
            /// Called when the playstate changes, except for the Error state (see OnError)
            /// </summary>
            /// <param name="player">The BackgroundAudioPlayer</param>
            /// <param name="track">The track playing at the time the playstate changed</param>
            /// <param name="playState">The new playstate of the player</param>
            /// <remarks>
            /// Play State changes cannot be cancelled. They are raised even if the application
            /// caused the state change itself, assuming the application has opted-in to the callback.
            /// 
            /// Notable playstate events: 
            /// (a) TrackEnded: invoked when the player has no current track. The agent can set the next track.
            /// (b) TrackReady: an audio track has been set and it is now ready for playack.
            /// 
            /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
            /// </remarks>
            protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
            {
                switch (playState)
                {
                    case PlayState.TrackEnded:
                        PlayNextTrack(player);
                        break;
    
                    case PlayState.TrackReady:
                        // The track to play is set in the PlayTrack method.
                        player.Play();
                        break;
                }
    
                NotifyComplete();
            }
    
    
            /// <summary>
            /// Called when the user requests an action using application/system provided UI
            /// </summary>
            /// <param name="player">The BackgroundAudioPlayer</param>
            /// <param name="track">The track playing at the time of the user action</param>
            /// <param name="action">The action the user has requested</param>
            /// <param name="param">The data associated with the requested action.
            /// In the current version this parameter is only for use with the Seek action,
            /// to indicate the requested position of an audio track</param>
            /// <remarks>
            /// User actions do not automatically make any changes in system state; the agent is responsible
            /// for carrying out the user actions if they are supported.
            /// 
            /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
            /// </remarks>
            protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
            {
                switch (action)
                {
                    case UserAction.Play:
                        PlayTrack(player);
                        break;
    
                    case UserAction.Pause:
                        player.Pause();
                        break;
    
                    case UserAction.SkipPrevious:
                        PlayPreviousTrack(player);
                        break;
    
                    case UserAction.SkipNext:
                        PlayNextTrack(player);
                        break;
                }
    
                NotifyComplete();
            }
    
    
            /// <summary>
            /// Called whenever there is an error with playback, such as an AudioTrack not downloading correctly
            /// </summary>
            /// <param name="player">The BackgroundAudioPlayer</param>
            /// <param name="track">The track that had the error</param>
            /// <param name="error">The error that occured</param>
            /// <param name="isFatal">If true, playback cannot continue and playback of the track will stop</param>
            /// <remarks>
            /// This method is not guaranteed to be called in all cases. For example, if the background agent 
            /// itself has an unhandled exception, it won't get called back to handle its own errors.
            /// </remarks>
            protected override void OnError(BackgroundAudioPlayer player, AudioTrack track, Exception error, bool isFatal)
            {
                if (isFatal)
                {
                    Abort();
                }
                else
                {
                    NotifyComplete();
                }
    
            }
    
            /// <summary>
            /// Called when the agent request is getting cancelled
            /// </summary>
            /// <remarks>
            /// Once the request is Cancelled, the agent gets 5 seconds to finish its work,
            /// by calling NotifyComplete()/Abort().
            /// </remarks>
            protected override void OnCancel()
            {
    
            }
        }
    }


    Tuesday, February 12, 2013 11:45 PM
  • any ideas?
    Thursday, February 14, 2013 11:02 PM
  • Help!!!
    Thursday, February 21, 2013 11:35 PM
  • Does the problem reproduce only with that particular stream? Can you get it to work using other sources ? Your problem might be a codec problem with the emulator.

    Also it would be helpful to know if you compiled your app as a 7.1 app or 8.0, and what devices and/or emulator modes you tested.

    -Mark


    Mark Chamberlain Sr. Escalation Engineer | Microsoft Developer Support | Windows Phone 8

    Tuesday, February 26, 2013 5:07 PM
  • I have problem with the flow I have to add "; stream.mp3."

    When I use the stream below error in emulator WP8.
    http://65.60.52.122:8700/; stream.mp3
    http://s5.voscast.com:7346/; stream.mp3

    The OnError method returns the error "-1072877856"

    The application was developed that have used the 7.1 version and works correctly, but when I try to use the emulator WP8 returns the error.

    thank you
    Alex Sandro

    an example of the app is available at the link below

    https://skydrive.live.com/?cid=4c9952dbfc52b1cf#cid=4C9952DBFC52B1CF&id=4C9952DBFC52B1CF%21146

    Saturday, March 02, 2013 8:39 PM
  • any ideas?
    Saturday, March 09, 2013 9:25 PM
  • Hi,

    I suspect that you need to URL-encode those strings before using them.

    HttpUtility.UrlEncode Method

    Hope this helps,
    Mark


    Mark Chamberlain Sr. Escalation Engineer | Microsoft Developer Support | Windows Phone 8

    Monday, March 11, 2013 3:02 PM
  • hi, I tried to use yohi, I tried to use your suggestion, but got no luck.ur suggestion, but got no luck.
    Wednesday, March 13, 2013 1:00 AM
  • i have same problem and i can't find something ..... if find something Alex where can help , please post here !

    Thursday, March 14, 2013 10:20 PM
  • Here is a checklist.

    1. The stream is not supported by the particular emulator or particular phone model.

    Supported media codecs

    2. The URL is bad or possibly needs encoding

    3. Internet connection problem. Wifi?

    4. Make sure the failing stream isn't simply currently down. Test via the desktop etc.

    5. A coding problem. Test other streams that otherwise work to make sure it isn't something wrong with your code.

    Hope this helps,
    Mark


    Mark Chamberlain Sr. Escalation Engineer | Microsoft Developer Support | Windows Phone 8

    Friday, March 15, 2013 2:20 PM
  • Hello Alex,

    The streams that you're attempting to play are using the Shoutcast streaming protocol. You can create an app that will play these streams on Windows Phone 7.5 as well as Windows Phone 8.0 by creating or leveraging a MediaStreamSource implementation of the Shoutcast protocol. MediaStreamSource is documented here:

    http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.media.mediastreamsource(v=vs.105).aspx

    Once you have a working MediaStreamSource for Shoutcast, you can also use it to play audio in the background. The Background Audio Streamer Sample shows how to do this:

    http://code.msdn.microsoft.com/wpapps/Background-Audio-Streamer-e85b8deb

    You might be interested to know that there's an open source MediaStreamSource implementation for Shoutcast. This code is not provided or supported by Microsoft:

    http://shoutcastmss.codeplex.com


    Rob Van Wicklen | Microsoft | Windows Phone Developer Platform

    Thursday, April 25, 2013 3:37 AM