problem: code that worked recently suddenly stopped working

actually i want to stream an audio file online in android and ios devices
so i used media player in android and avplayer in ios
it worked good in the first, i have checked them in emulators, and now they are suddenly stopped streaming/ playing, i dont know what actually happened to the code

even the code worked good in the previous day suddenly this morning they stopped working...need help ... thank you

Answers

  • JohnHJohnH GBMember ✭✭✭✭✭

    Error message? Exceptions? Which stopped working, Android or iOS, or both? You really need to provide more info for anyone to have, including example code that now doesn't work.

  • VenkataSivaprasadReddyPulagamVenkataSivaprasadReddyPulagam USMember ✭✭✭
    edited July 2016

    Thank you @JohnHair for your reply.
    actually there is no response ,even if i click on play button, it simple stands idle without any responses, i placed this code in my friends comptuer also but it dint make even a noise.

    this is my code
    both stopped working !

    in PCL

    InitializeComponent();
    var play = new Button()
    {
    Text = "Play/Pause",
    VerticalOptions = LayoutOptions.CenterAndExpand,
    HorizontalOptions = LayoutOptions.StartAndExpand,
    Command = new Command(() =>
    {
    DependencyService.Get().Play_Pause("http://www.montemagno.com/sample.mp3");
    })
    };
    var stop = new Button()
    {
    Text = " Stop ",
    VerticalOptions = LayoutOptions.CenterAndExpand,
    HorizontalOptions = LayoutOptions.StartAndExpand,
    Command = new Command(() =>
    {
    DependencyService.Get().Stop(true);
    })
    };

            StackLayout holder = new StackLayout()
            {
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children = { play, stop }
            };
            Content = new StackLayout()
            {
                Children = { holder }
            };
        }
    

    interface create in PCL services folder

    namespace LifeImprovementCommunity
    {
    public interface IAudioService
    {
    bool PlayMusic(String url);
    bool StopMusic(bool val);
    }
    }

    dependency in ios

    using System;
    using Xamarin.Forms;
    using LifeImprovementCommunity.iOS;
    using AVFoundation;
    using Foundation;

    [assembly : Dependency (typeof(AudioService))]
    namespace LifeImprovementCommunity.iOS
    {
    public class AudioService : IAudio
    {
    int clicks = 0;
    AVPlayer player;
    public AudioService ()
    {
    }

        public bool Play_Pause (string url)
        {
            if (clicks == 0) {
                this.player = new AVPlayer ();
                this.player = AVPlayer.FromUrl (NSUrl.FromString (url));
                this.player.Play ();
                clicks++;
            } else if (clicks % 2 != 0) {
                this.player.Pause ();
                clicks++;
    
            } else {
                this.player.Play ();
                clicks++;
            }
    
            return true;
        }
    
        public bool Stop (bool val)
        {
            this.player.Dispose ();
            clicks = 0;
            return true;
        }
    
    }
    

    }

    Dependency in Android

    using System;
    using Xamarin.Forms;
    using LifeImprovementCommunity.Droid;
    using Android.Media;

    [assembly : Dependency (typeof(AudioSerivce))]
    namespace LifeImprovementCommunity.Droid
    {
    public class AudioSerivce : IAudio
    {
    int clicks = 0;
    MediaPlayer player;

        public AudioSerivce ()
        {
        }
    
        public bool Play_Pause (string url)
        {
            if (clicks == 0) {
                this.player = new MediaPlayer ();
                this.player.SetDataSource (url);
                this.player.SetAudioStreamType (Stream.Music);
                this.player.PrepareAsync ();
                this.player.Start ();
                clicks++;
            } else if (clicks % 2 != 0) {
                this.player.Pause ();
                clicks++;
    
            } else {
                this.player.Start ();
                clicks++;
            }
    
    
            return true;
        }
    
        public bool Stop (bool val)
        {
            this.player.Stop ();
            clicks = 0;
            return true;
        }
    }
    

    }

  • PubuduGayanPubuduGayan NZMember ✭✭✭

    Hi @VenkataSivaprasadReddyPulagam check your PCL dotnet version, is it match with the other projects.

  • VenkataSivaprasadReddyPulagamVenkataSivaprasadReddyPulagam USMember ✭✭✭
    edited July 2016

    Hi @PubuduGayan ,
    Thankyou for your response
    i checked them , all are of same version, any other recomendations/suggestions...., ThankYou

Sign In or Register to comment.