本文整理汇总了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 ();
}
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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 ();
}
示例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();
}
示例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;
}
示例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;
}
示例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 ();
}
}
示例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");
}
}
示例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();
}
示例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();
}
示例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;
}
示例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 ();
};
}
示例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");
}
}