Example #1
0
        /// <summary>
        /// Event handler for the Button on the Page.
        /// </summary>
        /// <param name="sender">
        /// The button which was clicked.
        /// </param>
        /// <param name="e">
        /// The state when this event was generated.
        /// </param>
        private void OpenMedia(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.ShowDialog();

            Mp3MediaStreamSource mediaSource = new Mp3MediaStreamSource(ofd.File.OpenRead());

            me.SetSource(mediaSource);
        }
Example #2
0
        /// <summary>
        /// Handles the HTTP WebRequests' callback.
        /// </summary>
        /// <param name="asyncResult">the result of the callback</param>
        private void RequestCallback(IAsyncResult asyncResult)
        {
            HttpWebResponse response = request.EndGetResponse(asyncResult) as HttpWebResponse;
            Stream          s        = response.GetResponseStream();

            mss = new Mp3MediaStreamSource(s, response.ContentLength);
            Deployment.Current.Dispatcher.BeginInvoke(
                () =>
            {
                this.wp7AudioElement.Volume = 100;
                this.wp7AudioElement.SetSource(mss);
            });
        }
Example #3
0
 public void Dispose()
 {
     mSource = null;
 }
Example #4
0
 public Mp3AudioData(Stream s)
 {
     mSource = new Mp3MediaStreamSource(s);
 }
Example #5
0
        public void Init(Syscalls mSyscalls, Core mCore, Runtime mRuntime)
        {
            mSyscalls.maSoundPlay = delegate(int _data, int _offset, int _size)
            {
                mSyscalls.maSoundStop();
                Resource      audiores = mRuntime.GetResource(MoSync.Constants.RT_BINARY, _data);
                BoundedStream s        = new BoundedStream((Stream)audiores.GetInternalObject(), _offset, _size);

                // Read MIME type. Mp3MediaStreamSource is not clever enough to bypass it.
                StringBuilder sb = new StringBuilder();
                int           b;
                while ((b = s.ReadByte()) > 0)
                {
                    sb.Append((char)b);
                }
                if (b < 0)
                {
                    // The MIME type was interrupted.
                    // Bad stream. We don't want to play it.
                    return(-2);
                }
                if (sb.ToString() != "audio/mpeg")
                {
                    // We can only play MP3 files.
                    return(-3);
                }

                Mp3MediaStreamSource source = new Mp3MediaStreamSource(s);

                // all Controls code must be Dispatched to the proper thread,
                // or you'll get a fatal Exception.
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    mElement        = new MediaElement();
                    mElement.Volume = mVolume;
                    mElement.SetSource(source);
                    mElement.Play();
                });
                return(0);
            };

            mSyscalls.maSoundStop = delegate()
            {
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    if (mElement != null)
                    {
                        mElement.Stop();
                    }
                });
            };

            mSyscalls.maSoundIsPlaying = delegate()
            {
                int result = 0;
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    if (mElement != null)
                    {
                        MediaElementState s = mElement.CurrentState;
                        result = (s == MediaElementState.Buffering) || (s == MediaElementState.Playing) ? 1 : 0;
                    }
                });
                return(result);
            };

            mSyscalls.maSoundGetVolume = delegate()
            {
                return((int)mVolume);
            };

            mSyscalls.maSoundSetVolume = delegate(int _vol)
            {
                mVolume = _vol;
                if (mVolume > 100)
                {
                    mVolume = 100;
                }
                else if (mVolume < 0)
                {
                    mVolume = 0;
                }
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (mElement != null)
                    {
                        mElement.Volume = mVolume;
                    }
                });
            };
        }