当前位置: 首页>>代码示例>>C#>>正文


C# MediaPlayer.SetDataSource方法代码示例

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


在下文中一共展示了MediaPlayer.SetDataSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Play

 public void Play(string p_FilePath)
 {
     using (MediaPlayer player = new MediaPlayer()) {
         if (p_FilePath.IndexOf ("Content") > -1) {
             Android.Content.Res.AssetFileDescriptor af = Android.App.Application.Context.Assets.OpenFd (p_FilePath);
             player.SetDataSource (af.FileDescriptor, af.StartOffset, af.Length);
         } else {
             player.SetDataSource (Path.Combine(DataPath,p_FilePath));
         }
         player.Prepare ();
         player.Start ();
     }
 }
开发者ID:tianjing,项目名称:SayWordByPicture,代码行数:13,代码来源:MediaPlay.cs

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: videoDuration

 public int videoDuration(string filename)
 {
     MediaPlayer video = new MediaPlayer();
     FileInputStream fs = new FileInputStream(filename);
     FileDescriptor fd = fs.FD;
     video.SetDataSource(fd);
     video.Prepare();
     int length = video.Duration;
     video.Reset();
     video.Release();
     return length;
 }
开发者ID:chimpinano,项目名称:WowZapp-Android,代码行数:12,代码来源:videoPlay.cs

示例8: findDuration

 public int findDuration(string filename)
 {
     MediaPlayer wav = new MediaPlayer();
     FileInputStream fs = new FileInputStream(filename);
     FileDescriptor fd = fs.FD;
     wav.SetDataSource(fd);
     wav.Prepare();
     int length = wav.Duration;
     wav.Reset();
     wav.Release();
     return length;
 }
开发者ID:chimpinano,项目名称:WowZapp-Android,代码行数:12,代码来源:AudioManager.cs

示例9: play

		void play(string fullPath)
		{
			ISurfaceHolder holder = videoView.Holder;
			holder.SetType (SurfaceType.PushBuffers);
			holder.AddCallback( this );
			player = new  MediaPlayer ();
			Android.Content.Res.AssetFileDescriptor afd = this.Assets.OpenFd(fullPath);
			if  (afd != null )
			{
				player.SetDataSource (afd.FileDescriptor, afd.StartOffset, afd.Length);
				player.Prepare ();
				player.Start ();
			}
		}
开发者ID:softsan,项目名称:List-view-demo-android,代码行数:14,代码来源:DetailView.cs

示例10: AndroidMusic

 public AndroidMusic(AssetFileDescriptor afd)
 {
     this.mp = new MediaPlayer ();
     try {
         mp.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
         mp.Prepare();
         isPrepared = true;
         mp.SetOnCompletionListener(this);
         mp.SetOnSeekCompleteListener(this);
         mp.SetOnPreparedListener(this);
         mp.SetOnVideoSizeChangedListener(this);
     } catch {
         throw new ApplicationException("Couldn't load music");
     }
 }
开发者ID:Paludan,项目名称:BeerRun,代码行数:15,代码来源:AndroidMusic.cs

示例11: PlayAudioFile

		public void PlayAudioFile(string fileName)
		{
			var player = new MediaPlayer();
			var fd = global::Android.App.Application.Context.Assets.OpenFd(fileName);
			player.Prepared += (s, e) =>
			{
				player.Start();
			};

			player.Completion += (s, e) =>
			{
			};

			player.SetDataSource(fd.FileDescriptor, fd.StartOffset, fd.Length);
			player.Prepare();
		}
开发者ID:QuickBlox,项目名称:quickblox-dotnet-sdk,代码行数:16,代码来源:AudioService.cs

示例12: StartVideoPlayback

        public void StartVideoPlayback(SurfaceView surface, string FilePath)
        {
            if (_player != null)
              {
            StopVideoPlayback();
              }
              _player = new MediaPlayer();

              ISurfaceHolder holder = surface.Holder;
              holder.SetType(Android.Views.SurfaceType.PushBuffers);
              holder.SetFixedSize(400, 300);

              _player.SetDisplay(holder);
              _player.SetDataSource(FilePath);
              _player.Prepare();
              _player.Start();
        }
开发者ID:rsatter,项目名称:MonoCross,代码行数:17,代码来源:VideoPlayer.cs

示例13: playAudio

 public void playAudio(string filePath)
 {
     if (player == null)
     {
         player = new MediaPlayer();
         player.SetDataSource(filePath);
         player.Prepare();
         player.Start();
     }
     else
     {
         player.Reset();
         player.SetDataSource(filePath);
         player.Prepare();
         player.Start();
     }
     isPlaying = true;
 }
开发者ID:JRolandros,项目名称:DeezerXamarin,代码行数:18,代码来源:AudioService.cs

示例14: OnCreate

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

			// Carega o layout "main" na view principal
			SetContentView (Resource.Layout.Main);

			// Pega o botão do recurso de layout e coloca um evento nele
			Button button = FindViewById<Button> (Resource.Id.button);

			vv = FindViewById<VideoView> (Resource.Id.video_view);
			pb = FindViewById<ProgressBar> (Resource.Id.progress_bar);
			MediaController mc = new MediaController(this);
			mp = new MediaPlayer ();

			pb.SetOnTouchListener (this);

			var uri = Android.Net.Uri.Parse ("http://3gpfind.com/vid/load/Movie%20Trailer/Predators(3gpfind.com).3gp");
			vv.SetOnPreparedListener (this);
			vv.SetVideoURI(uri);
			vv.SetMediaController(mc);
			mc.SetMediaPlayer(vv);
			mc.SetAnchorView(vv);

			button.Click += delegate {
				mc.Show();
				if (!ready)
				{
					holder = vv.Holder;
					holder.SetType (SurfaceType.PushBuffers);
					holder.AddCallback(this);
					mp.SetDataSource(this, uri);
					mp.SetOnPreparedListener(this);
					mp.Prepare();
					ready = true;
				}

				mp.Start();
//				vv.Start();

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

示例15: AndroidMusic

        public AndroidMusic(AssetFileDescriptor assetDescriptor)
        {
            mediaPlayer = new MediaPlayer();
            try
            {
                mediaPlayer.SetDataSource(assetDescriptor.FileDescriptor,
                                          assetDescriptor.StartOffset,
                                          assetDescriptor.Length);
                mediaPlayer.Prepare();
                isPrepared = true;
                mediaPlayer.SetOnCompletionListener(this);
                mediaPlayer.SetOnSeekCompleteListener(this);
                mediaPlayer.SetOnPreparedListener(this);
                mediaPlayer.SetOnVideoSizeChangedListener(this);

            }
            catch (Exception e)
            {
                throw new SystemException("Couldn't load music");
            }
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:21,代码来源:AndroidMusic.cs


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