如何用C#播放amr文件
1个回答
展开全部
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入要打开的文件");
string filePath = Console.ReadLine();
Console.WriteLine("请输入文件名");
string fileName = Console.ReadLine();
baseFile bf = GetFile(filePath, fileName);
if(bf != null){
bf.OpenFile();
}
Console.ReadKey();
}
static baseFile GetFile(string filePath, string fileName)
{
baseFile bf = null;
string strextension = Path.GetExtension(fileName);
switch (strextension)
{
//amr
case ".amr":
bf = new TxtFile(filePath, fileName);
break;
case ".html":
bf = new TxtFile(filePath, fileName);
break;
case ".avi":
bf = new TxtFile(filePath, fileName);
break;
}
return bf;
}
}
class baseFile
{
//字段.属性.构造函数.函数.索引器
private string _filePath;
public string FilePath
{
get { return _filePath; }
set { _filePath = value; }
}
public string FileName { get; set; }
public baseFile(string filePath,string fileName) {
this.FileName = fileName;
this.FilePath = filePath;
}
//打开函数
public void OpenFile()
{
ProcessStartInfo psi = new ProcessStartInfo(this.FilePath+"\\"+this.FileName);
Process pro = new Process();
pro.StartInfo= psi;
pro.Start();
}
}
class TxtFile : baseFile
{
public TxtFile(string filePath , string fileName):base(filePath,fileName) {
}
}
class MP4File : baseFile
{
public MP4File(string filePath, string fileName) : base(filePath, fileName) { }
}
}
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入要打开的文件");
string filePath = Console.ReadLine();
Console.WriteLine("请输入文件名");
string fileName = Console.ReadLine();
baseFile bf = GetFile(filePath, fileName);
if(bf != null){
bf.OpenFile();
}
Console.ReadKey();
}
static baseFile GetFile(string filePath, string fileName)
{
baseFile bf = null;
string strextension = Path.GetExtension(fileName);
switch (strextension)
{
//amr
case ".amr":
bf = new TxtFile(filePath, fileName);
break;
case ".html":
bf = new TxtFile(filePath, fileName);
break;
case ".avi":
bf = new TxtFile(filePath, fileName);
break;
}
return bf;
}
}
class baseFile
{
//字段.属性.构造函数.函数.索引器
private string _filePath;
public string FilePath
{
get { return _filePath; }
set { _filePath = value; }
}
public string FileName { get; set; }
public baseFile(string filePath,string fileName) {
this.FileName = fileName;
this.FilePath = filePath;
}
//打开函数
public void OpenFile()
{
ProcessStartInfo psi = new ProcessStartInfo(this.FilePath+"\\"+this.FileName);
Process pro = new Process();
pro.StartInfo= psi;
pro.Start();
}
}
class TxtFile : baseFile
{
public TxtFile(string filePath , string fileName):base(filePath,fileName) {
}
}
class MP4File : baseFile
{
public MP4File(string filePath, string fileName) : base(filePath, fileName) { }
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询