如何使用WPF用户界面框架编译EasyPlayPro-Win版本网页无插件视频播放器?

WPF提供了统一的编程模型、语言和框架,同时也提供了全新的多媒体交互用户图形界面,对研发人员来说,它最终将减少提供最佳用户体验和通信逻辑所需的代码行数。

目前TSINGSEE青犀视频开发的网页视频播放器EasyPlayPro-win播放器有MFC和winform版本,基于优化的考虑,我们研发了使用WPF框架编译EasyPlayPro-win播放器库。

1、先大致制作一个简单的界面,界面大致如下

xmal代码如下,里面包含各种事件,来处理逻辑程序:

<Window x:Class="EasyPlayerPro.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="EasyPlayerPro" Height="563" Width="785" Loaded="Onload" Closing="Window_Closing">
    <Grid HorizontalAlignment="Center">
        <StackPanel Height="395" HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Top" Width="751" Orientation="Horizontal">
            <Image Height="228" Name="image1" Stretch="Fill" Width="631" />
        </StackPanel>
        <Slider Height="23" HorizontalAlignment="Center" Margin="12,417,0,0" Name="slider1" VerticalAlignment="Top" Width="739" GotMouseCapture="slider1_GotMouseCapture" Thumb.DragCompleted="slider1_DragCompleted" IsSnapToTickEnabled="True" />
        <TextBox Height="23" HorizontalAlignment="Center" Margin="12,446,0,0" Name="textBox1" VerticalAlignment="Top" Width="739" TextAlignment="Left" VerticalContentAlignment="Center" Text="http://demo.easydss.com:10080/fvod/ULJyMRhZR/video.m3u8" />
        <StackPanel Height="49" HorizontalAlignment="Stretch" Margin="12,475,0,0" Name="stackPanel2" VerticalAlignment="Top" Width="739" Orientation="Horizontal">
            <Button Content="开始" Height="23" Name="StartBtn" Width="40" Click="StartBtn_Click" />
            <Button Content="停止" Height="23" Name="StopBtn" Width="40" Click="StopBtn_Click" />
            <Button Content="暂停" Height="23" Name="PauseBtn" Width="40" Click="PauseBtn_Click" />
            <Button Content="单帧" Height="23" Name="SingleFrameBtn" Width="40" Click="SingleFrameBtn_Click" />
            <Button Content="播放" Height="23" Name="PlayBtn" Width="40" Click="PlayBtn_Click" />
            <Button Content="速度" Height="23" Name="SpeedBtn" Width="40" Click="SpeedBtn_Click" />
            <ComboBox Height="23" Name="comboBox1" Width="65" SelectedIndex="9">
                <ComboBoxItem Content="10" />
                <ComboBoxItem Content="20" />
                <ComboBoxItem Content="30" />
                <ComboBoxItem Content="40" />
                <ComboBoxItem Content="50" />
                <ComboBoxItem Content="60" />
                <ComboBoxItem Content="70" />
                <ComboBoxItem Content="80" />
                <ComboBoxItem Content="90" />
                <ComboBoxItem Content="100" Visibility="Collapsed" />
                <ComboBoxItem Content="200" />
                <ComboBoxItem Content="300" />
                <ComboBoxItem Content="400" />
                <ComboBoxItem Content="500" />
                <ComboBoxItem Content="600" />
            </ComboBox>
            <Button Content="全屏" Height="23" Name="FullScreenBtn" Width="40" Click="FullScreenBtn_Click" />
            <Button Content="退出" Height="23" Name="CloseBtn" Width="40" Click="CloseBtn_Click" />
            <Label Content="时长:00分:00秒/00分:00秒" Height="28" Name="label1" Width="353" HorizontalAlignment="Right" IsEnabled="True" HorizontalContentAlignment="Right" />
        </StackPanel>
    </Grid>
</Window>	

2、引用libEasyplayerpro.dll动态库,把需要授权、播放、暂停等所需要的功能引用上。

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Authorize", CallingConvention = CallingConvention.Cdecl)]
static extern int EasyPlayerPro_Authorize(string license);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Create", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr EasyPlayerPro_Create();

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Release", CallingConvention = CallingConvention.Cdecl)]
static extern void EasyPlayerPro_Release(IntPtr player);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Open", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr EasyPlayerPro_Open(IntPtr player, string file, IntPtr hwnd, EASY_VIDEO_RENDER_TYPE render_type, EASY_VIDEO_SCALE_MODE video_mode, EASY_STREAM_LINK_MODE link_mode, int speed, int valume, int probesize, int max_analyze_duration);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Close", CallingConvention = CallingConvention.Cdecl)]
 static extern void EasyPlayerPro_Close(IntPtr player);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Play", CallingConvention = CallingConvention.Cdecl)]
static extern void EasyPlayerPro_Play(IntPtr player);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_StepPlay", CallingConvention = CallingConvention.Cdecl)]
static extern void EasyPlayerPro_StepPlay(IntPtr player, int type);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Pause", CallingConvention = CallingConvention.Cdecl)]
static extern void EasyPlayerPro_Pause(IntPtr player);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Seek", CallingConvention = CallingConvention.Cdecl)]
static extern void EasyPlayerPro_Seek(IntPtr player, System.Int64 ms);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Resize", CallingConvention = CallingConvention.Cdecl)]
static extern void EasyPlayerPro_Resize(IntPtr player, int type, int x, int y, int w, int h);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Snapshot", CallingConvention = CallingConvention.Cdecl)]
static extern int EasyPlayerPro_Snapshot(IntPtr player, string file, int w, int h, int wait);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Record", CallingConvention = CallingConvention.Cdecl)]
static extern int EasyPlayerPro_Record(IntPtr player, string filePath, int duration);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Stoprecord", CallingConvention = CallingConvention.Cdecl)]
static extern int EasyPlayerPro_Stoprecord(IntPtr player);

[DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Setparam", CallingConvention = CallingConvention.Cdecl)]
static extern void EasyPlayerPro_Setparam(IntPtr player, EASY_PARAM_ID id, ref IntPtr param);

        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Getparam", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_Getparam(IntPtr player, EASY_PARAM_ID id, ref Int64 param);

3、实现功能逻辑,并播放视频在界面上,输入可用url,点击播放,可出现画面。

有一点需要注意:Image这个标签需转为Handle,再把Handle传入EasyPlayerPro_Open的第三个参数上。具体的如下:

IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(image1)).Handle;
mPlayer = EasyPlayerPro_Open(mPlayer, this.textBox1.Text, hwnd, EASY_VIDEO_RENDER_TYPE.EASY_VIDEO_RENDER_TYPE_GDI,
                    EASY_VIDEO_SCALE_MODE.EASY_VIDEO_MODE_LETTERBOX, EASY_STREAM_LINK_MODE.EASY_STREAM_LINK_TCP,
                    Convert.ToInt32(comboBox1.Text), 0, 1024 * 1024, 1000000);

4、全部逻辑代码如下,大家可以参考:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Runtime.InteropServices;
using System.Windows.Threading;
using System.Windows.Interop; 

namespace EasyPlayerPro
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        // adev render type
        public enum EASY_AUDIO_RENDER_TYPE
        {
            //waveout
            EASY_AUDIO_RENDER_TYPE_WAVEOUT = 0,
        };

        // vdev render type
        public enum EASY_VIDEO_RENDER_TYPE
        {
            EASY_VIDEO_RENDER_TYPE_GDI = 0,
            EASY_VIDEO_RENDER_TYPE_D3D,
            //	EASY_VIDEO_RENDER_TYPE_OPENGL,
            EASY_VIDEO_RENDER_TYPE_MAX_NUM,
        };

        // render mode
        public enum EASY_VIDEO_SCALE_MODE
        {
            //拉伸充满显示区域
            EASY_VIDEO_MODE_STRETCHED,
            //按比例缩放到显示区域
            EASY_VIDEO_MODE_LETTERBOX,
            EASY_VIDEO_MODE_MAX_NUM,
        };

        // link mode
        public enum EASY_STREAM_LINK_MODE
        {
            //按比例缩放到显示区域
            EASY_STREAM_LINK_UDP = 0,
            //拉伸充满显示区域
            EASY_STREAM_LINK_TCP,
            EASY_STREAM_LINK_MODE_NUM,
        };

        // audio visual effect
        public enum EASY_AUDIO_VISUAL_EFFECT_MODE
        {
            EASY_AUDIO_VISUAL_EFFECT_DISABLE,
            EASY_AUDIO_VISUAL_EFFECT_WAVEFORM,
            EASY_AUDIO_VISUAL_EFFECT_SPECTRUM,
            EASY_AUDIO_VISUAL_EFFECT_MAX_NUM,
        };

        // hwaccel type 视频渲染硬件加速类型
        public enum EASY_VIDEO_HARDWARE_ACCEL_TYPE
        {
            EASY_VIDEO_HWACCEL_TYPE_NONE,
            EASY_VIDEO_HWACCEL_TYPE_DXVA2,
            EASY_VIDEO_HWACCEL_TYPE_MAX_NUM,
        };

        public enum EASY_PARAM_ID
        {
            //++ public
            // duration & position
            EASY_PARAM_MEDIA_DURATION = 0x1000,
            EASY_PARAM_MEDIA_POSITION,

            // media detail info
            EASY_PARAM_MEDIA_INFO,
            EASY_PARAM_VIDEO_WIDTH,
            EASY_PARAM_VIDEO_HEIGHT,

            // video display mode
            EASY_PARAM_VIDEO_MODE,

            // audio volume control
            EASY_PARAM_AUDIO_VOLUME,

            // playback speed control
            EASY_PARAM_PLAY_SPEED,
            EASY_PARAM_PLAY_SPEED_TYPE,

            // video decode thread count
            EASY_PARAM_DECODE_THREAD_COUNT,

            // visual effect mode
            EASY_PARAM_VISUAL_EFFECT,

            // audio/video sync diff
            EASY_PARAM_AVSYNC_TIME_DIFF,

            // player event callback
            EASY_PARAM_PLAYER_CALLBACK,
            // player event/audio/video callback userdata
            EASY_PARAM_PLAYER_USERDATA,

            // audio/video stream
            EASY_PARAM_AUDIO_STREAM_TOTAL,
            EASY_PARAM_VIDEO_STREAM_TOTAL,
            EASY_PARAM_SUBTITLE_STREAM_TOTAL,
            EASY_PARAM_AUDIO_STREAM_CUR,
            EASY_PARAM_VIDEO_STREAM_CUR,
            EASY_PARAM_SUBTITLE_STREAM_CUR,

            //++ for media record 
            EASY_PARAM_RECORD_TIME,
            EASY_PARAM_RECORD_PIECE_ID,
            //-- for media record
            //-- public

            //++ for adev
            EASY_PARAM_ADEV_RENDER_TYPE = 0x2000,
            EASY_PARAM_ADEV_GET_CONTEXT,
            EASY_PARAM_ADEV_SET_MUTE,
            //-- for adev

            //++ for vdev
            EASY_PARAM_VDEV_RENDER_TYPE = 0x3000,
            EASY_PARAM_VDEV_FRAME_RATE,
            EASY_PARAM_VDEV_GET_CONTEXT,
            EASY_PARAM_VDEV_POST_SURFACE,
            EASY_PARAM_VDEV_GET_D3DDEV,
            EASY_PARAM_VDEV_D3D_ROTATE,
            //-- for vdev

            //++ for render
            EASY_PARAM_RENDER_UPDATE = 0x4000,
            EASY_PARAM_RENDER_START_PTS,
            //-- for render
        };

        // EasyPlayerPro接口函数声明
        //
        //授权
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Authorize", CallingConvention = CallingConvention.Cdecl)]
        static extern int EasyPlayerPro_Authorize(string license);

        //初始化创建播放器实例(该接口可多次调用创建多个实例)
        // 		返回值				- Easy_PlayerPro_Handle 指针类型,指向 easyplayerpro 对象句柄
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Create", CallingConvention = CallingConvention.Cdecl)]
        static extern IntPtr EasyPlayerPro_Create();

        //销毁播放器实例
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Release", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_Release(IntPtr player);

        //打开播放视频
        // 	EasyPlayerPro_Open     打开一个媒体流或者媒体文件进行播放,同时返回一个 player 对象指针
        // 		fileUrl				- 文件路径(可以是网络流媒体的 URL)
        // 		hWnd				- Win32 的窗口句柄/其他平台渲染显示设备句柄
        //		render_mode			- 视频渲染模式,详见EASY_VIDEO_RENDER_TYPE
        //		video_mode			- 视频显示模式,详见EASY_VIDEO_SCALE_MODE
        //		link_mode			- 流连接模式,目前只对RTSP流有效,设置rtp over tcp/udp,	详见EASY_STREAM_LINK_MODE
        //		speed				- 播放速度,0-100慢放,100以上快放
        //		valume				- 播放音量,-255 - +255
        // 		返回值				- Easy_PlayerPro_Handle 指针类型,指向 easyplayerpro 对象句柄
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Open", CallingConvention = CallingConvention.Cdecl)]
        static extern IntPtr EasyPlayerPro_Open(IntPtr player, string file, IntPtr hwnd, EASY_VIDEO_RENDER_TYPE render_type, EASY_VIDEO_SCALE_MODE video_mode, EASY_STREAM_LINK_MODE link_mode, int speed, int valume, int probesize, int max_analyze_duration);

        //关闭视频
        // 	EasyPlayerPro_Close    关闭播放
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Close", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_Close(IntPtr player);

        //播放视频
        // 	EasyPlayerPro_Play     开始播放,注意:媒体流或者文件打开后不需要调用此函数即开始播放,
        // 							此函数在暂停、单步播放的时候调用,返回正常播放逻辑
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Play", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_Play(IntPtr player);

        //单帧播放视频
        // 	EasyPlayerPro_StepPlay 单步播放,一次播放一帧,调用EasyPlayerPro_Play返回正常播放
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        //		type				- 单步播放类型,1-往前 2-向后
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_StepPlay", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_StepPlay(IntPtr player, int type);

        //暂停视频
        // 	EasyPlayerPro_Pause		暂停播放,调用EasyPlayerPro_Play返回正常播放
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Pause", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_Pause(IntPtr player);

        //挑转播放进度
        // 	EasyPlayerPro_Seek     跳转到指定位置播放
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        // 		seek				- 指定位置,以毫秒为单位
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Seek", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_Seek(IntPtr player, System.Int64 ms);

        //设置窗口显示区域
        // 	EasyPlayerPro_Resize   设置显示区域,有两种显示区域,视频显示区和视觉效果显示区
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        // 		type				- 指定区域类型  0 - video rect, 1 - audio visual effect rect
        // 		x,y,width,height	- 指定显示矩形区域
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Resize", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_Resize(IntPtr player, int type, int x, int y, int w, int h);

        //截图
        // 	EasyPlayerPro_Snapshot 视频播放截图
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        // 		filePath			- 图片存放路径,以.xxx结束(xxx 目前只支持 jpeg 格式)
        // 		width, height       - 指定图片宽高,如果 <= 0 则默认使用视频宽高
        // 		waittime			- 是否等待截图完成 0 - 不等待,>0 等待超时 ms 为单位
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Snapshot", CallingConvention = CallingConvention.Cdecl)]
        static extern int EasyPlayerPro_Snapshot(IntPtr player, string file, int w, int h, int wait);

        // 	EasyPlayerPro_Record   视频播放录像
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        // 		filePath			- 图片存放路径,以.xxx结束(xxx 目前只支持 mp4 格式)
        // 		duration			- 指定图片宽高,如果 <= 0 则默认使用视频宽高
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Record", CallingConvention = CallingConvention.Cdecl)]
        static extern int EasyPlayerPro_Record(IntPtr player, string filePath, int duration);

        // 	EasyPlayerPro_Stoprecord   视频播放停止录像
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Stoprecord", CallingConvention = CallingConvention.Cdecl)]
        static extern int EasyPlayerPro_Stoprecord(IntPtr player);


        //设置参数
        // 	EasyPlayerPro_Setparam 设置参数
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        // 		param_id			- 参数ID,见EASY_PARAM_ID定义
        // 		param				- 参数指针
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Setparam", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_Setparam(IntPtr player, EASY_PARAM_ID id, ref IntPtr param);

        //获取参数
        // 	EasyPlayerPro_Setparam 获取参数
        // 		player				- 指向 EasyPlayerPro_Open 返回的 player 对象
        // 		param_id			- 参数ID,见EASY_PARAM_ID定义
        // 		param				- 参数指针
        [DllImport("libEasyplayerpro.dll", EntryPoint = "EasyPlayerPro_Getparam", CallingConvention = CallingConvention.Cdecl)]
        static extern void EasyPlayerPro_Getparam(IntPtr player, EASY_PARAM_ID id, ref Int64 param);

        private string ACTIVE_KEY = "授权key";

        private IntPtr mPlayer = IntPtr.Zero;
        int totalTime = 0;
        int alreadyTime = 0;
        bool bInit = false;
        bool bPlaying = false;

        private DispatcherTimer timer1 = new DispatcherTimer();
        private DispatcherTimer timer2 = new DispatcherTimer();
        public MainWindow()
        {
            InitializeComponent();

            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Interval = new TimeSpan(0, 0, 0, 0, 100);

            timer2.Tick += new EventHandler(timer2_Tick);
            timer2.Interval = new TimeSpan(0, 0, 0, 0, 100);
        }

        private void Onload(object sender, RoutedEventArgs e)
        {
            this.comboBox1.Text = "100";
            int nRet = EasyPlayerPro_Authorize(ACTIVE_KEY);
            if (nRet <= 0)
            {
                MessageBox.Show("激活码不合法或已过期!", "提示", MessageBoxButton.OK);
            }
            string strTitle = "EasyPlayerPro    " + "授权剩余时间:" + nRet + " 天";
            this.Title = strTitle;
            mPlayer = EasyPlayerPro_Create();
            bInit = true;
        }
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (bPlaying)
            {
                EasyPlayerPro_Close(mPlayer);
            }
            if (bInit)
            {
                EasyPlayerPro_Release(mPlayer);
            }
            mPlayer = IntPtr.Zero;
            bInit = false;
        }


        // 开始
        private void StartBtn_Click(object sender, RoutedEventArgs e)
        {
            if (!bPlaying)
            {
                IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(image1)).Handle;
                mPlayer = EasyPlayerPro_Open(mPlayer, this.textBox1.Text, hwnd, EASY_VIDEO_RENDER_TYPE.EASY_VIDEO_RENDER_TYPE_GDI,
                    EASY_VIDEO_SCALE_MODE.EASY_VIDEO_MODE_LETTERBOX, EASY_STREAM_LINK_MODE.EASY_STREAM_LINK_TCP,
                    Convert.ToInt32(comboBox1.Text), 0, 1024 * 1024, 1000000);
                timer1.Start();
                timer2.Start();
                bPlaying = true;
            }
            else
            {
                MessageBox.Show("先关闭视频!");
            }
        }

        //停止
        private void StopBtn_Click(object sender, RoutedEventArgs e)
        {
            EasyPlayerPro_Close(mPlayer);
            bPlaying = false;
        }

        //暂停
        private void PauseBtn_Click(object sender, RoutedEventArgs e)
        {
            EasyPlayerPro_Pause(mPlayer);
        }

        //单帧
        private void SingleFrameBtn_Click(object sender, RoutedEventArgs e)
        {
            EasyPlayerPro_StepPlay(mPlayer, 1);
        }

        //播放
        private void PlayBtn_Click(object sender, RoutedEventArgs e)
        {
            EasyPlayerPro_Play(mPlayer);
        }

        //速度
        private void SpeedBtn_Click(object sender, RoutedEventArgs e)
        {
            IntPtr param = new IntPtr();
            param = (IntPtr)Convert.ToInt32(comboBox1.Text);
            EasyPlayerPro_Setparam(mPlayer, EASY_PARAM_ID.EASY_PARAM_PLAY_SPEED, ref param);
        }

        //全屏
        private void FullScreenBtn_Click(object sender, RoutedEventArgs e)
        {

        }

        //退出
        private void CloseBtn_Click(object sender, RoutedEventArgs e)
        {

        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            if (mPlayer != IntPtr.Zero)
            {
                Int64 param = 0;
                if (totalTime <= 0)
                {
                    Int64 ltotal = 0;
                    EasyPlayerPro_Getparam(mPlayer, EASY_PARAM_ID.EASY_PARAM_MEDIA_DURATION, ref param);
                    ltotal = param;
                    if (ltotal > 1)
                    {
                        totalTime = (int)(Int64)ltotal / 1000;
                        slider1.Maximum = (int)totalTime;
                    }
                }

                EasyPlayerPro_Getparam(mPlayer, EASY_PARAM_ID.EASY_PARAM_MEDIA_POSITION, ref param);
                alreadyTime = (int)(Int64)param / 1000;

                if (totalTime > 0)
                {
                    if (totalTime - alreadyTime <= 1)
                    {
                        timer1.Stop();
                        timer2.Stop();
                        label1.Content = "时长:00分:00秒/00分:00秒";
                        mPlayer = IntPtr.Zero;
                    }
                    else
                    {
                        label1.Content = string.Format("时长:{0:00}分:{1:00}秒/{2:00}分:{3:00}秒", alreadyTime / 60, (alreadyTime) % 60, totalTime / 60, (totalTime) % 60);
                    }
                }
                else
                {
                    label1.Content = string.Format("时长:{0:00}分:{1:00}秒/../..", alreadyTime / 60, (alreadyTime) % 60);
                }
            }
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (slider1.Maximum > 0 && alreadyTime >= 0 && alreadyTime < slider1.Maximum)
            {
                slider1.Value = alreadyTime;
            }
        }

        private void slider1_GotMouseCapture(object sender, MouseEventArgs e)
        {
            Console.WriteLine("slider1_GotMouseCapture");
            timer2.Stop();
        }
        private void slider1_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            if (mPlayer == IntPtr.Zero) return;
            EasyPlayerPro_Seek(mPlayer, (int)slider1.Value * 1000);
            timer2.Start();
        }


    }
}
posted on 2021-03-03 17:25  TSINGSEE  阅读(234)  评论(1编辑  收藏  举报