问题描述
usingSystem;usingSystem.Threading;usingAndroid.App;usingAndroid.Content;usingAndroid.Runtime;usingAndroid.Views;usingAndroid.Widget;usingAndroid.OS;usingAndroid.Media;usingAndroid.Util;namespacemediaPlayer{[Activity(Label="mediaPlayer",MainLauncher=true,Icon="@drawable/icon")]publicclassMainActivity:Activity,MediaPlayer.IOnCompletionListener{intcount=1;MediaPlayeridPlayer;TextViewtv;protectedoverridevoidOnCreate(Bundlebundle){base.OnCreate(bundle);//Setourviewfromthe"main"layoutresourceSetContentView(Resource.Layout.Main);//Getourbuttonfromthelayoutresource,//andattachaneventtoitButtonbutton=FindViewById<Button>(Resource.Id.MyButton);button.Click+=delegate{button.Text=string.Format("{0}clicks!",count++);};ButtonplayId=FindViewById<Button>(Resource.Id.button1);playId.Click+=playId_Click;Buttonstop=FindViewById<Button>(Resource.Id.button2);stop.Click+=playNet_Click;Buttonpause=FindViewById<Button>(Resource.Id.button3);pause.Click+=playFile_Click;Buttonvideo=FindViewById<Button>(Resource.Id.button4);video.Click+=video_Click;tv=FindViewById<TextView>(Resource.Id.textView1);}voidvideo_Click(objectsender,EventArgse){Intentintent=newIntent(this,typeof(Video));StartActivity(intent);}voidplayFile_Click(objectsender,EventArgse){idPlayer.Pause();}voidplayNet_Click(objectsender,EventArgse){idPlayer.Stop();//intposition=idPlayer.CurrentPosition/1000;//Toast.MakeText(this,position.ToString(),ToastLength.Short).Show();}voidplayId_Click(objectsender,EventArgse){idPlayer=newMediaPlayer();if(idPlayer!=null){idPlayer.SetDataSource(this.Resources.OpenRawResourceFd(Resource.Raw.yshq).FileDescriptor);idPlayer.SetOnCompletionListener(this);idPlayer.Prepare();idPlayer.Start();Threadthread=newThread(newThreadStart(Run));thread.Start();}}privatevoidRun(){while(true){Thread.Sleep(1000);inti=(idPlayer.CurrentPosition/1000);RunOnUiThread(()=>{//打印当前音乐播放当前时间和总时间//当前时间输出正确//总共时间输出415(总共时间为15s)tv.Text=i.ToString()+"&&&"+(idPlayer.Duration).ToString();});if(i==15){break;}}}publicvoidOnCompletion(MediaPlayermp){mp.Stop();mp.Release();}}}
解决方案
解决方案二:
Pause之后也不能播放了?
解决方案三:
Pause和Stop之后再调用Start又重新播放
解决方案四:
有没有跟Pause对应的Resume什么的方法?Play可能就是重新播放的方法
解决方案五:
楼主,我做了一下测试是可以的啊,以下是我的代码,我刚开始接触monoforandroid的。以后多多交流namespaceApp1{[Activity(Label="App1",MainLauncher=true,Icon="@drawable/icon")]publicclassMainActivity:Activity{intcount=0;MediaPlayermp=newMediaPlayer();protectedoverridevoidOnCreate(Bundlebundle){base.OnCreate(bundle);//Setourviewfromthe"main"layoutresourceSetContentView(Resource.Layout.Main);//Getourbuttonfromthelayoutresource,//andattachaneventtoitButtonbutton=FindViewById<Button>(Resource.Id.MyButton);SurfaceViewsfv=FindViewById<SurfaceView>(Resource.Id.surfaceView1);button.Click+=delegate{button.Text=string.Format("{0}clicks!",++count);};button.Click+=(sender,e)=>{//播放视频代码sfv.Click+=Sfv_Click;mp.SetDisplay(sfv.Holder);mp.SetDataSource("/storage/external_storage/sdcard1/111.mp4");mp.Prepare();mp.Start();};}privatevoidSfv_Click(objectsender,EventArgse){if(mp.IsPlaying){mp.Pause();}else{mp.Start();}}}}