private void tsmiPlayer_Click(object sender, EventArgs e) { //获取播放路径 string videoPath = this.dgvVedioList.CurrentRow.Cells["path"].Value.ToString(); if (!File.Exists(videoPath)) { MessageBox.Show("文件不存在!", "提示"); return; } //创建单例 FrmPlayer myPlayer = FrmPlayer.GetInstance(); bool result = myPlayer.Play(videoPath); if (result) { //显示 myPlayer.Show(); } else { //释放 myPlayer.Dispose(); } }
//检查并创建唯一实例 public static FrmPlayer GetInstance() { if (uniquePlayer == null) { uniquePlayer = new FrmPlayer(); } return(uniquePlayer); }
//关闭过程中将实例引用设为null private void FrmPlayer_FormClosing(object sender, FormClosingEventArgs e) { FrmPlayer.uniquePlayer = null; }