Я пытаюсь воспроизвести аудиофайл в silverlight, используя WCF, язык C #, я не получаю никаких ошибок в своем приложении, хотя mp3 не воспроизводится.
Вот что у меня есть:
stream fileStream;
private void DownloadMusic_Click( object sender, RoutedEventArgs e )//this is the button that plays the music
{
FileServiceClient FSC = new FileServiceClient();
FSC.DownloadTestCompleted += new EventHandler<DownloadTestCompletedEventArgs>( FSC_DownloadTestCompleted );
FSC.DownloadTestAsync( FileSearch.Text );
}
void FSC_DownloadTestCompleted( object sender, DownloadTestCompletedEventArgs e )
{
FileObject fileObject;
if ( e.Error == null )
{
if ( e.Result != null )
{
fileObject = e.Result;
fileStream = new MemoryStream( fileObject.FileStream );
mediaElement1.SetSource( fileStream );
mediaElement1.AutoPlay = false;
mediaElement1.Play();
ResultBlock.Text = "Song is playing . . .";
}
else
{
ResultBlock.Text = "Song could not be found";
}
}
}
Служба:
public FileObject DownloadTest( string fileName )
{
FileStream fileStream = null;
BinaryReader reader = null;
string filePath = "";
byte[] fileBytes;
try
{
filePath = Path.Combine( HttpContext.Current.Server.MapPath( "." ), "Pictures", fileName);
if ( File.Exists( filePath ) )
{
fileStream = new FileStream( filePath, FileMode.Open, FileAccess.Read );
reader = new BinaryReader( fileStream );
fileBytes = reader.ReadBytes( (int)fileStream.Length );
return new FileObject() { FileName = fileName, FileStream = fileBytes };
}
return null;
}
catch ( Exception )
{
return null;
}
}
Интерфейс:
namespace WCF_Silverlight_UploadFile.Web
{
[ServiceContract]
public interface IFileService
{
[OperationContract]
bool UploadTest(FileObject file);
[OperationContract]
FileObject DownloadTest(string fileName);
}
[DataContract]
public class FileObject
{
[DataMember]
public string FileName { get; set; }
[DataMember]
public byte[] FileStream { get; set; }
[DataMember]
public string FileType { get; set; }
}
}
Вся помощь будет оценена.Спасибо