• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Media.MediaPlayer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Android.Media.MediaPlayer的典型用法代码示例。如果您正苦于以下问题:C# MediaPlayer类的具体用法?C# MediaPlayer怎么用?C# MediaPlayer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MediaPlayer类属于Android.Media命名空间,在下文中一共展示了MediaPlayer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: PlayVideo

		private void PlayVideo(SurfaceTexture surfaceTexture)
		{
			DoCleanUp();
			try
			{

				path = "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8";
				if (path == "")
				{
					// Tell the user to provide a media file URL.
					Toast.MakeText(this, "Please edit MediaPlayerDemo_setSurface Activity, " + "and set the path variable to your media file path." + " Your media file must be stored on sdcard.", ToastLength.Long).Show();
					return;
				}
				// Create a new media player and set the listeners
				mMediaPlayer = new MediaPlayer(this, true);
				mMediaPlayer.SetDataSource(path);
				if (surf == null)
				{
					surf = new Surface (surfaceTexture);
				}
				mMediaPlayer.SetSurface(surf);
				mMediaPlayer.PrepareAsync();
				mMediaPlayer.SetOnBufferingUpdateListener(this);
				mMediaPlayer.SetOnCompletionListener(this);
				mMediaPlayer.SetOnPreparedListener(this);
				VolumeControlStream = Stream.Music;

			}
			catch (Exception e)
			{
				Log.Error(TAG, "error: " + e.Message, e);
			}
		}
开发者ID:huguodong,项目名称:VitamioBinding-1.0,代码行数:33,代码来源:MediaPlayerDemo_setSurface.cs


示例2: InitAndPlayAudio

		public void InitAndPlayAudio (string trackSource)
		{
			var resourceId = GetRawResourceId(trackSource);
			Console.WriteLine("Resource id for " + trackSource + " = " 
				+ (resourceId.HasValue ? resourceId.Value.ToString() : "(null)"));


			if (player != null) {
				if (player.IsPlaying) {
					player.Stop ();
				}
				player.Reset ();
				player.Release ();
				player = null;
			}

			if (resourceId.HasValue) {
				player = MediaPlayer.Create (Application.Context, resourceId.Value);

				// do not use player.Prepare () -- MediaPlayer.Create takes care of this

				player.Completion += (sender, e) => {
					player.Reset ();
					player.Release ();
					player = null;
					AudioState = AudioState.Stopped;
				};

				AudioState = AudioState.Playing;
				player.Start ();
			}
		}
开发者ID:instantiator,项目名称:BAASBox.SampleApp,代码行数:32,代码来源:LocalAdaptor.cs


示例3: OnSurfaceTextureAvailable

        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            nn_surface = new Surface (surface);

            RelativeLayout.LayoutParams l;
            DisplayMetrics metrics = new DisplayMetrics();
            nn_activity.WindowManager.DefaultDisplay.GetMetrics(metrics);
            l = new RelativeLayout.LayoutParams(metrics.HeightPixels, metrics.WidthPixels);
            l.AddRule(LayoutRules.CenterInParent);
            float scale = (metrics.HeightPixels * 1.0f) / (metrics.WidthPixels * 1.0f);
            textureview.ScaleX = scale;
            textureview.LayoutParameters=l;

            try {
                nn_mediaplayer= new MediaPlayer();
                //String uriPath = "android.resource://"+nn_activity.PackageName+"/raw/Tap5050_About";
                nn_mediaplayer.SetDataSource(nn_activity,global::Android.Net.Uri.Parse("android.resource://"+nn_activity.PackageName +"/"+ Resource.Raw.Tap5050_About));
                nn_mediaplayer.SetSurface(nn_surface);
                nn_mediaplayer.Prepare();
                nn_mediaplayer.Prepared+= (object sender, EventArgs e) => {
                    (sender as MediaPlayer).Start ();
                };
                nn_mediaplayer.Completion+= (object sender, EventArgs e) => {
                    (sender as MediaPlayer).SeekTo (0);
                    (sender as MediaPlayer).Pause ();
                };

            }catch(Exception e){
                Toast.MakeText (nn_activity,"Sorry,Can not play the video",ToastLength.Long).Show();
            }
        }
开发者ID:MADMUC,项目名称:TAP5050,代码行数:31,代码来源:AboutShowTutorialFragment.cs


示例4: OnElementChanged

        protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
        {
            base.OnElementChanged(e);
            if (Element == null)
                return;

            player = new MediaPlayer();
            timer = new Timer(1000);
            timer.Elapsed += timer_Elapsed;

            player.Prepared += (sender, args) =>
              {
                  try
                  {
                      player.SeekTo(0);
                      player.Start();
                      timer.Start();
                  }
                  catch
                  {
                  }
              };

            if (string.IsNullOrWhiteSpace(Player.Url))
                return;

            InitPlayer();

        }
开发者ID:Adam--,项目名称:Hanselman.Forms,代码行数:29,代码来源:AudioPlayerRenderer.cs


示例5: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            ActionBar.Hide();
            SetContentView(Resource.Layout.Main);
            cover = FindViewById<RelativeLayout>(Resource.Id.titleScreen);
            player = MediaPlayer.Create(this, Resource.Raw.avril_14th);
            toggleMusic = FindViewById<ToggleButton>(Resource.Id.toggleMusic);
            player.Start();
            player.Looping = true;

            cover.Click += delegate
            {
                StartActivity(typeof(Login));
            };


            toggleMusic.Click += (o, s) =>

            {
                if (toggleMusic.Checked)
                {
                    player.Start();
                    toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPause);

                }
                else
                {
                    toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPlay);
                    player.Pause();
                }
            };


        }
开发者ID:knervous,项目名称:MemoryBox,代码行数:35,代码来源:MainActivity.cs


示例6: PlayWavFile

        public bool PlayWavFile(string fileName)
        {
            _mediaPlayer = MediaPlayer.Create(global::Android.App.Application.Context, Resource.Raw.ding_persevy);
            _mediaPlayer.Start();

            return true;
        }
开发者ID:JohanDeLijser,项目名称:SimpleAudioForms,代码行数:7,代码来源:AudioService.cs


示例7: StartPlayer

        public void StartPlayer(AssetFileDescriptor filePath)
        {
            if (player == null)
            {
                player = new MediaPlayer();
                player.Reset();
                /*

                player.SetDataSource(filePath.FileDescriptor, filePath.StartOffset, filePath.Length);
                player.Prepare();
                player.Start();
                 * */

            }
            if(player != null)
            {
                //player.Reset();
                player.SetDataSource(filePath.FileDescriptor, filePath.StartOffset, filePath.Length);
                player.Prepare();
                if (AudioPosition > 0)
                {
                   player.SeekTo(AudioPosition);
                }
                player.Start();
            }
        }
开发者ID:ConundrumSystems,项目名称:PowerpointAppStyle,代码行数:26,代码来源:AudioPlayer.cs


示例8: OnCreate

		protected override void OnCreate(Bundle savedInstanceState)
		{
			base.OnCreate(savedInstanceState);

			// Create your application here
			SetContentView(Resource.Layout.Dictionary);

			mimgHome = FindViewById<ImageView>(Resource.Id.limgHome);
			mlstWords = FindViewById<ListView>(Resource.Id.llstWords);
			mpWord = MediaPlayer.Create(this, Resource.Raw.cebuano_woman);
			mimgHome.SetImageResource(Resource.Drawable.home);
			//srch = FindViewById<SearchView>(Resource.Id.search);

			try
			{
				var db = new SQLiteConnection(path);

				var words = db.Table<Dictionary>();
				foreach (var w in words)
				{
					mlistWords.Add(new DictWordModel { strCeb = w.CebuanoWord, strTag = w.TagalogWord });
				}
				mlstWords.Adapter = new DictWordAdapter(this, mlistWords);
				adapters = new ArrayAdapter<DictWordModel>(this, Android.Resource.Layout.SimpleListItem1, mlistWords);
			}
			catch (SQLiteException ex)
			{
				string m = ex.Message;
			}

			//lstWords.Adapter = new DictWordAdapter (this, mlistWords);
			mimgHome.Click += (object sender, EventArgs e) => StartActivity(typeof(actMenu));
			//mlstWords.ItemClick += (object sender, AdapterView .ItemClickEventArgs e) => mpWord.Start();
		}
开发者ID:jejeboom,项目名称:Cebuanizer,代码行数:34,代码来源:actDictionary.cs


示例9: PlaySound

		public async void PlaySound(Media media)
		{
			if (media == null || media.Data == null || media.Data.Length == 0)
				return;

			if (_soundPlayer != null) {
				_soundPlayer.Stop ();
				_soundPlayer.Reset ();
			} else {
				_soundPlayer = new MediaPlayer ();
			}

			try {
				// Open file and read from FileOffset FileSize bytes for the media
				using (Java.IO.RandomAccessFile file = new Java.IO.RandomAccessFile (media.FileName, "r")) {
					await _soundPlayer.SetDataSourceAsync(file.FD,media.FileOffset,media.FileSize);
					file.Close();
				}

				// Start media
				if (_soundPlayer != null) {
					_soundPlayer.Prepare();
					_soundPlayer.Start ();
				} else
					throw new InvalidCastException(String.Format ("Audio file format of media {0} is not valid", media.Name));
			} catch (Exception ex) {
				String s = ex.ToString();
			}
		}
开发者ID:Surfoo,项目名称:WF.Player,代码行数:29,代码来源:Sound.cs


示例10: OnProgressChanged

        public override void OnProgressChanged(WebView view, int newProgress)
        {
            base.OnProgressChanged(view, newProgress);

            _context.SetProgress(newProgress * 100);

            if (newProgress == 100)
            {
                _context.Title = view.Title;

                bool soundEnabled = PreferenceManager.GetDefaultSharedPreferences(_context.ApplicationContext).GetBoolean("sounds", false);

                if (soundEnabled)
                {
                    _mediaPlayer = MediaPlayer.Create(_context.ApplicationContext, Resource.Raw.inception_horn);
                    _mediaPlayer.Completion += delegate { _mediaPlayer.Release(); };
                    _mediaPlayer.Start();
                }

                // add this page to the history
                using (SQLiteDatabase db = _historyDataHelper.WritableDatabase)
                {
                    var values = new ContentValues();
                    values.Put("Title", view.Title);
                    values.Put("Url", view.Url);
                    values.Put("Timestamp", DateTime.Now.Ticks);

                    db.Insert("history", null, values);
                }
            }
            else
            {
                _context.Title = _context.ApplicationContext.Resources.GetString(Resource.String.title_loading);
            }
        }
开发者ID:jorik041,项目名称:Sample-Projects,代码行数:35,代码来源:CustomWebChromeClient.cs


示例11: PlaySoundAsync

        public Task PlaySoundAsync(string filename)
        {
            // Create media player
            var player = new MediaPlayer();

            // Create task completion source to support async/await
            var tcs = new TaskCompletionSource<bool> ();

            // Open the resource
            var fd = Xamarin.Forms.Forms.Context.Assets.OpenFd (filename);

            // Hook up some events
            player.Prepared += (s, e) => {
                player.Start();
            };

            player.Completion += (sender, e) => {
                tcs.SetResult(true);
            };

            // Initialize
            player.SetDataSource (fd.FileDescriptor);
            player.Prepare ();

            return tcs.Task;
        }
开发者ID:chrfalch,项目名称:SoundPlayer,代码行数:26,代码来源:AndroidSoundProvider.cs


示例12: OnPrepared

		public void OnPrepared (MediaPlayer mp)
		{
			mp.Looping = true;
			int h = mp.VideoHeight;
			int w = mp.VideoWidth;

			mp.SetOnVideoSizeChangedListener (this);
			mp.SetOnBufferingUpdateListener (this);
			mp.SetOnSeekCompleteListener (this);
			mp.SetOnCompletionListener (this);

			int time = vv.Duration;
			int time_elapsed = vv.CurrentPosition;
			pb.Progress = time_elapsed;

			var timer = new CountDown (time, 500);
			timer.Tick += (long millisUntilFinished) => {
				float a = vv.CurrentPosition;
				float b = vv.Duration;

				pb.Progress = (int)(a/b*100);
			};
			timer.Finish += () => {
				Toast.MakeText (this, "Timer Finished", ToastLength.Short).Show ();
			};

			Toast.MakeText (this, "Video Prepared", ToastLength.Short).Show ();
		}
开发者ID:rogeriofabricio,项目名称:XamarinCursoCross,代码行数:28,代码来源:MainActivity.cs


示例13: OnCreateView

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.HomeScreen, container, false);
            infoButton = view.FindViewById<Button>(Resource.Id.infoButton);
            player = MediaPlayer.Create(view.Context, Resource.Raw.avril_14th);
            toggleMusic = view.FindViewById<ToggleButton>(Resource.Id.toggleMusic);
            cover = view.FindViewById<RelativeLayout>(Resource.Id.titleScreen);

            Xamarin.Insights.Initialize(XamarinInsights.ApiKey, view.Context);
            CurrentPlatform.Init();

            player.Start();
            player.Looping = true;

            cover.Click += delegate
            {
                facebookLogin.Invoke(this, new LoginEventArgs());
            };

            toggleMusic.Click += (o, s) => {

                if (toggleMusic.Checked)
                {
                    player.Start();
                    toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPause);
                }
                else {
                    toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPlay);
                    player.Pause();
                }
            };

            return view;
        }
开发者ID:knervous,项目名称:MemBox1,代码行数:34,代码来源:HomeScreenFragment.cs


示例14: OnError

        public bool OnError(MediaPlayer mp, Android.Media.MediaError e, int s)
        {
#if DEBUG
            Console.WriteLine("{0}", e.ToString());
#endif
            return true;
        }
开发者ID:nodoid,项目名称:Webview,代码行数:7,代码来源:videoplayer.cs


示例15: Play

        public void Play(string filePath)
        {
            try
            {
                if (player == null)
                {
                    player = new MediaPlayer();
                }
                else
                {
                    player.Reset();
                }

                // This method works better than setting the file path in SetDataSource. Don't know why.
                var file = new File(filePath);
                var fis = new FileInputStream(file);

                player.SetDataSource(fis.FD);

                //player.SetDataSource(filePath);
                player.Prepare();
                player.Start();
            }
            catch (Exception ex)
            {
                System.Console.Out.WriteLine(ex.StackTrace);
            }
        }
开发者ID:shawancyb,项目名称:VoiceTimeCounter,代码行数:28,代码来源:AudioPlayer.cs


示例16: PlaySound

 /// <summary>
 /// Method that plays the sound on Android.
 /// </summary>
 public void PlaySound(SoundboardItem item)
 {
     player = new MediaPlayer ();
     var fd = Xamarin.Forms.Forms.Context.Assets.OpenFd (item.FileName + ".mp3");
     player.SetDataSource (fd.FileDescriptor);
     player.Prepare ();
     player.Start ();
 }
开发者ID:sander1095,项目名称:DnD_Soundboard_Edres,代码行数:11,代码来源:Soundplayer_Android.cs


示例17: Reset

		void Reset () {
			if (_player == null)
				_player = new MediaPlayer ();
			else
				_player.Reset ();
			_player.SetAudioStreamType (Stream.Music);
			_player.SetVolume (_volume, _volume);
		}
开发者ID:jpernst,项目名称:GameStack,代码行数:8,代码来源:AndroidMusicChannel.cs


示例18: OnCreate

		public override void OnCreate ()
		{
			base.OnCreate ();

			songPos = 0;
			player = new MediaPlayer ();
			InitMusicPlayer ();
		}
开发者ID:jackpatmcgrath,项目名称:MyMusicPlayer,代码行数:8,代码来源:MusicService.cs


示例19: Play

 public override void Play(string filename)
 {
     AssetFileDescriptor afd = Assets.OpenFd(filename);
     player = new MediaPlayer();
     player.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
     player.Completion += DidFinishPlaying;
     player.Prepare();
     player.Start();
 }
开发者ID:papagenoo,项目名称:BabylonMono,代码行数:9,代码来源:SoundPlayerIml.cs


示例20: Play

        public bool Play()
        {
            _player = MediaPlayer.Create(global::Android.App.Application.Context, Resource.Raw._01yes);
            _player.Start();
            _player.Completion += delegate
            {
                _player.Release();
            };

            return true;
        }
开发者ID:bronsonmcn,项目名称:AoESoundBoard,代码行数:11,代码来源:PlayAudio_Android.cs



注:本文中的Android.Media.MediaPlayer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# OS.Handler类代码示例发布时间:2022-05-24
下一篇:
C# Locations.LocationManager类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap