silverlight 播放器,丑丑版

silverlight 播放器,丑丑版

 看到园子里的大虾们写了播放器,这不,我也写了一个和大家在此分享一下.

  分别是前台和后台;

备注:参考了一些园子里朋友的代码片段,该播放器是一个独立的 操作界面

需要传入 音频路径 .为了测试 您可以直接赋值给url


1

<
Grid x:Name
=

LayoutRoot

Background
=

White

Height
=

237

Width
=

499

>


2


3

<
MediaElement Height
=

0

HorizontalAlignment
=

Left

Margin
=

12,12,0,0

Name
=

myElement

VerticalAlignment
=

Top

Width
=

0

LoadedBehavior
=

Manual

MediaEnded
=

myElement_MediaEnded


/>


4

<
Button Content
=

播放

Height
=

23

HorizontalAlignment
=

Left

Margin
=

10,41,0,0

Name
=

button1

VerticalAlignment
=

Top

Width
=

75

Click
=

button1_Click


/>


5

<
Button Content
=

暂停

Height
=

23

HorizontalAlignment
=

Left

Margin
=

111,41,0,0

Name
=

button2

VerticalAlignment
=

Top

Width
=

75

Click
=

button2_Click


/>


6

<
Button Content
=

停止

Height
=

23

HorizontalAlignment
=

Left

Margin
=

211,41,0,0

Name
=

button3

VerticalAlignment
=

Top

Width
=

75

Click
=

button3_Click


/>


7

<
Button Content
=

静音

Height
=

23

HorizontalAlignment
=

Left

Margin
=

319,41,0,0

Name
=

button4

VerticalAlignment
=

Top

Width
=

75

Click
=

button4_Click


/>


8

<
Label Height
=

23

HorizontalAlignment
=

Left

Margin
=

138,84,0,0

Name
=

label1

VerticalAlignment
=

Top

Width
=

120


/>


9

<
TextBlock Height
=

23

HorizontalAlignment
=

Left

Margin
=

10,113,0,0

Name
=

textBlock2

Text
=

当前进度;

VerticalAlignment
=

Top


/>


10

<
Slider Height
=

23

HorizontalAlignment
=

Left

Margin
=

64,108,0,0

Name
=

slider1

VerticalAlignment
=

Top

Width
=

293

Value
=

{Binding ElementName=myElement,Path=Position}

ValueChanged
=

slider1_ValueChanged


/>


11

<
Label Height
=

23

HorizontalAlignment
=

Right

Margin
=

0,113,12,0

Name
=

label2

VerticalAlignment
=

Top

Width
=

132


/>


12

<
Label Height
=

23

HorizontalAlignment
=

Left

Margin
=

12,84,0,0

Name
=

label3

VerticalAlignment
=

Top

Width
=

120


/>


13

<
TextBlock Height
=

23

HorizontalAlignment
=

Left

Margin
=

259,147,0,0

Name
=

textBlock5

Text
=

音量;

VerticalAlignment
=

Top


/>


14

<
Slider Height
=

23

HorizontalAlignment
=

Left

Margin
=

295,141,0,0

Name
=

slider2

VerticalAlignment
=

Top

Width
=

100

ValueChanged
=

slider2_ValueChanged


/>


15

<
Label Height
=

23

HorizontalAlignment
=

Left

Margin
=

389,136,0,0

Name
=

label4

VerticalAlignment
=

Top

Width
=

59


/>


16

<
Button Content
=

下载

Height
=

23

HorizontalAlignment
=

Left

Margin
=

412,41,0,0

VerticalAlignment
=

Top

Name
=

btnDown

Width
=

75

Click
=

btnDown_Click_1


/>


17

<
Button Content
=

关闭

Height
=

23

HorizontalAlignment
=

Left

Margin
=

424,214,0,0

Name
=

button5

VerticalAlignment
=

Top

Width
=

75

Click
=

button5_Click


/>


18

</
Grid
>


19

=后台:

ContractedBlock.gif
ExpandedBlockStart.gif
View Code


1
using
System;

2
 
using
System.Collections.Generic;

3
 
using
System.Linq;

4
 
using
System.Text;

5

using
System.Windows;

6

using
System.Windows.Controls;

7

using
System.Windows.Data;

8

using
System.Windows.Documents;

9

using
System.Windows.Input;

10

using
System.Windows.Media;

11

using
System.Windows.Media.Imaging;

12

using
System.Windows.Navigation;

13

using
System.Windows.Shapes;

14

using
System.IO;

15

using
System.Diagnostics;

16


17

namespace
eOMS.CR

18
{


19

///

<summary>


20

///
PlayWindow.xaml 的交互逻辑

21

///

</summary>


22



23

public

partial

class
PlayWindow : UserControl

24
{


25

string
Url
=

string
.Empty;
//
音频文件路径


26


string
sPath
=

string
.Empty;
//
保存文件路径


27


string
isplay
=


0

;
//
标记是否已经处于播放状态


28

System.Windows.Threading.DispatcherTimer timer
=

new
System.Windows.Threading.DispatcherTimer();

29


30

public
PlayWindow()

31
{


32
InitializeComponent();

33


34
}

35


36

public
PlayWindow(
string
SoundUrl)

37
{


38


39

try


40
{


41


42
InitializeComponent();

43
Url
=
SoundUrl;

44
myElement.Source
=

new
Uri(Url, UriKind.Absolute);

45
timer.Interval
=

new
TimeSpan(
1000
);

46
timer.Tick
+=

new
EventHandler(timer_Tick);

47
timer.Start();

48
}

49

catch
(Exception ex)

50
{


51


52
MessageBox.Show(ex.Message);

53


54
}

55


56
}

57

void
timer_Tick(
object
sender, EventArgs e)

58
{


59
label2.Content
=

string
.Format(

60


{0}{1:00}:{2:00}:{3:00}

,

61


播放进度:

,

62
myElement.Position.Hours,

63
myElement.Position.Minutes,

64
myElement.Position.Seconds);

65
label3.Content
=

string
.Format(

下载进度:{0:##%}

, myElement.DownloadProgress);

66


67
}

68


69


70

private

void
InitializePropertyValues()

71
{


72

//
myElement.Volume = (double)volumeSlider.Value;

73

//
myElement.Source = new Uri(Url, UriKind.Absolute);


74

}

75

///

<summary>


76

///
下载按钮引发的事件

77

///

</summary>


78

///

<param name=”sender”></param>


79

///

<param name=”e”></param>


80


//
播放进度


81


private

void
slider1_ValueChanged(
object
sender, RoutedPropertyChangedEventArgs
<
double
>
e)

82
{


83


84

try


85
{


86


87

if
( isplay
==

1

)

88
{


89

int
value
=
(
int
)slider1.Value;

90

int
myvalue
=
(
int
)myElement.NaturalDuration.TimeSpan.TotalSeconds;

91
TimeSpan ts
=

new
TimeSpan(
0
,
0
,
0
,
0
, value);

92

//
myElement.Position = TimeSpan.FromSeconds((myvalue* value) / 10);


93

myElement.Position
=
ts;

94
}

95


96


97
}

98

catch
(Exception ex)

99
{


100


101

throw
ex;

102
}

103


104
}

105

///

<summary>


106

///
播放

107

///

</summary>


108

///

<param name=”sender”></param>


109

///

<param name=”e”></param>


110


private

void
button1_Click(
object
sender, RoutedEventArgs e)

111
{


112
myElement.Play();

113
isplay
=


1

;

114
}

115

///

<summary>


116

///
暂停

117

///

</summary>


118

///

<param name=”sender”></param>


119

///

<param name=”e”></param>


120


private

void
button2_Click(
object
sender, RoutedEventArgs e)

121
{


122
isplay
=


0

;

123
myElement.Pause();

124
}

125

///

<summary>


126

///
停止

127

///

</summary>


128

///

<param name=”sender”></param>


129

///

<param name=”e”></param>


130


private

void
button3_Click(
object
sender, RoutedEventArgs e)

131
{


132
isplay
=


0

;

133
myElement.Stop();

134
}

135

///

<summary>


136

///
静音

137

///

</summary>


138

///

<param name=”sender”></param>


139

///

<param name=”e”></param>


140


private

void
button4_Click(
object
sender, RoutedEventArgs e)

141
{


142
myElement.IsMuted
=

!
myElement.IsMuted;

143
}

144

///

<summary>


145

///
音量控制

146

///

</summary>


147

///

<param name=”sender”></param>


148

///

<param name=”e”></param>


149


private

void
slider2_ValueChanged(
object
sender, RoutedPropertyChangedEventArgs
<
double
>
e)

150
{

151

//
音量控制


152


double
d
=
(
double
)(((
double
)slider2.Value)
/

10
);

153
myElement.Volume
=
d;

154
label4.Content
=
(
double
.Parse(d.ToString(

F2

))
*

100
)
+


%

;

155
}

156

///

<summary>


157

///
下载操作

158

///

</summary>


159

///

<param name=”sender”></param>


160

///

<param name=”e”></param>


161


private

void
btnDown_Click_1(
object
sender, RoutedEventArgs e)

162
{


163


164
System.Windows.Forms.SaveFileDialog sf
=

new
System.Windows.Forms.SaveFileDialog();

165
sf.Filter
=


音频文件|*.wav

;

166

if
( sf.ShowDialog()
==
System.Windows.Forms.DialogResult.OK)

167
{


168
String targetPath
=
sf.FileName;

169
System.IO.File.Copy(Url, targetPath,
true
);

170
}

171


172


173
}

174

///

<summary>


175

///
隐藏当前窗口

176

///

</summary>


177

///

<param name=”sender”></param>


178

///

<param name=”e”></param>


179


private

void
button5_Click(
object
sender, RoutedEventArgs e)

180
{

181
myElement.Stop();

182
myElement.Close();

183

this
.LayoutRoot.Visibility
=
Visibility.Hidden;

184
}

185


186

private

void
myElement_MediaEnded(
object
sender, RoutedEventArgs e)

187
{


188
isplay
=


0

;

189
}

190


191


192
}

193
}

转载于:https://www.cnblogs.com/benbenfishfish/archive/2011/06/28/2092401.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110601.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 26Region_tarim logai toplam

    26Region_tarim logai toplam给出 n 个点的一棵树,多次询问两点之间的最短距离。注意:边是无向的。所有节点的编号是 1,2,…,n。输入格式第一行为两个整数 n 和 m。n 表示点数,m 表示询问次数;下来 n−1 行,每行三个整数 x,y,k,表示点 x 和点 y 之间存在一条边长度为 k;再接下来 m 行,每行两个整数 x,y,表示询问点 x 到点 y 的最短距离。树中结点编号从 1 到 n。输出格式共 m 行,对于每次询问,输出一行询问结果。数据范围2≤n≤104,1≤m≤2×104,0<k≤1

  • asp.net的code-Behind技术

    新建一个VS.NET下的项目..看到ASPX,RESX和CS三个后缀的文件了吗??这个就是代码分离.实现了HTML代码和服务器代码分离.方便代码编写和整理.code-Behind:asp.net中的术

    2021年12月20日
  • mysql读写分离原理详解(主从复制和读写分离)

    主库记录二进制日志。在每次准备提交事务完成数据更新前,主库将数据更新的事件记录到二进制日志中。MySQL会按事务提交的顺序而非每条语句的执行顺序来记录二进制日志。在记录二进制日志后,主库会告诉存储引擎可以提交事务了。下一步,备库将主库的二进制日志复制到其本地的中继日志中。首先,备库会启动一个工作线程,称为I/O线程,I/O线程跟主库建立一个普通的客户端连接,然后在主库启动一个特殊的二进制转储线程,…

  • LOJ10049_基金012498

    LOJ10049_基金012498LOJ10049Trie裸题(虽然我写这SB题写了快一小时)对字符串建树的同时刷答案,有两种情况:经过了一个字符串的词尾(即过了一个标记点)一直在另一个字符串里走(没有让树长出新枝)#include&lt;bits/stdc++.h&gt;#definegt()(p1==p2&amp;&amp;(p2=(p1=buf)+fread(buf,1,1000000,std…

  • idea如何集成svn_集成吊顶步骤分解图

    idea如何集成svn_集成吊顶步骤分解图idea从项目窗口跳到打开项目选项窗口操作之后即可跳到如下界面第一步:下载svn的客户端,通俗一点来说就是小乌龟啦!官网下载地址:Downloads·TortoiseSVN下载之后直接安装就好了,但是要注意这里,选择安装所有的命令行客户端工具,默认是不安装的,如果不安装,svn中的bin目录下就会没有svn.exe,这个待会会用到,所以一点要注意哦。(都是坑啊)然后就下一步下一步就安装好了。第二步:如果已经搭建好了svn服务的话,就要开始在idea中配置相关.

  • 栈和队列讲解_栈和队列的优缺点

    栈和队列讲解_栈和队列的优缺点目录1、栈(1)栈的概念及结构(2)栈的实现2、队列(1)队列的概念及结构(2)队列的实现前言:栈和队列是在顺序表和链表的延伸,如果前面的顺序表和链表你已经掌握了的话,栈和队列对你来说应该就是小菜一碟了。1、栈(1)栈的概念及结构栈:一种特殊的线性表,其只允许在固定的一端进行插入和删除元素操作。进行数据插入和删除操作的一端称为栈顶,另一端称为栈底。栈中的数据元素遵守后进先出LIFO(LastInFirstOut)的原则。压栈:栈的插入操作叫做进栈/压栈..

    2022年10月30日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号