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)


相关推荐

  • 数据系统架构——Lambda architecture(Lambda架构)

    数据系统架构——Lambda architecture(Lambda架构)传统系统的问题“我们正在从IT时代走向DT时代(数据时代)。IT和DT之间,不仅仅是技术的变革,更是思想意识的变革,IT主要是为自我服务,用来更好地自我控制和管理,DT则是激活生产力,让别人活得比你好”——阿里巴巴董事局主席马云。数据量从M的级别到G的级别到现在T的级、P的级别。数据量的变化数据管理系统(DBMS)和数仓系统(DW)也在悄然的变化着。

  • 精通Python爬虫框架Scrapy_爬虫经典案例

    精通Python爬虫框架Scrapy_爬虫经典案例Scrapy,Python开发的一个快速、高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据。Scrapy用途广泛,可以用于数据挖掘、监测和自动化测试.其最初是为了页面抓取(更确切来说,网络抓取)所设计的,后台也应用在获取API所返回的数据(例如AmazonAssociatesWebServices)或者通用的网络爬虫.Scrapy吸引人的地…

  • python进阶(3)json文件与python字典的转化[通俗易懂]

    python进阶(3)json文件与python字典的转化[通俗易懂]序列化与反序列化按照某种规则,把内存中的数据保存到文件中,文件是一个字节序列,所以必须要把内存数据转换成为字节序列,输出到文件,这就是序列化;反之,从文件的字节恢复到内存,就是反序列化;pytho

  • Microsoft Office Excel 不能访问文件 的解决办法

    Microsoft Office Excel 不能访问文件 的解决办法

  • ubuntu nginx安装配置_PHP开发环境搭建步骤

    ubuntu nginx安装配置_PHP开发环境搭建步骤一、说明正在尝试基于nginx+php搭建web服务器,中途遇到不少问题。挣扎了三四个小时终于完成了,这里分享下经验。实验环境操作系统:Ubuntu18.0464位nginx:1.14.0php:7.2.17-0php-fram:php7.2-fpm二、实验步骤1、安装必要程序以及依赖#安装程序包sudoapt-getinstallphp7.2…

  • IP地址和物理地址有什么区别

    IP地址和物理地址有什么区别

    2021年10月22日

发表回复

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

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