fuliqi
2024-08-29 4163c93761115c7524ef74a557a1f5e01eafb429
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
package com.ycl.api.YS.playback.play;
 
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.util.Common;
import com.ycl.api.YS.lib.NetDEVSDKLib.*;
 
import javax.swing.*;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
 
/**
 * 
 * @introduction PlayBack
 * @description Support NVR/VMS
 */
public class Playback {
    
    /**
     * 
     * @introduction Playback by URL
     * @description  Calling the interface of NETDEV_PlayBackByUrl
     *
     */
    public static void playByURL() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0) {
            JOptionPane.showMessageDialog(null, "Please select an online channel.");
            return;
        }
        if(NetDemo.RecordTable.getSelectedRow()<0) {
            JOptionPane.showMessageDialog(null, "No file,please choose a file");
            return;
        }  
        if(null != NetDemo.lpPlayHandle) {
            JOptionPane.showMessageDialog(null, "Please stop playing first.");
            return;
        }
        NetDemo.jButtonStopPlayback.setEnabled(true);
        NetDemo.jButtonMic.setVisible(false);
        NetDemo.jSliderLiveMicSound.setVisible(false);
        NetDemo.jLabelLiveSound2.setVisible(false);
        NetDemo.jLableLiveMicSound.setVisible(false);
        NetDemo.jLabelLiveViewStreamUrl.setText(null);
        
        Pointer ReplayUrl=new Memory(260);
        boolean bRet= NetDemo.netdevsdk.NETDEV_GetReplayUrl(NetDemo.lpUserID, NetDemo.ChannelID, 0, ReplayUrl);
        byte[] szReplayUrl=ReplayUrl.getByteArray(0, 260);
        String pszReplayUrl=null;
        try {
            pszReplayUrl=new String(szReplayUrl,"GB2312");
            NetDemo.jLabelLiveViewStreamUrl.setText(pszReplayUrl);
        }catch(UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        
        if(NetDemo.RecordTable.getRowCount()<=0) {
            JOptionPane.showMessageDialog(null, "No file,please a file");
            return;
        }
        int row=NetDemo.RecordTable.getSelectedRow();
        String Beginstr=(String)NetDemo.RecordTable.getValueAt(row, 0);
        String Endstr=(String)NetDemo.RecordTable.getValueAt(row, 1);
        if(bRet) {
            NETDEV_PLAYBACKCOND_S pstPlayBackCond=new NETDEV_PLAYBACKCOND_S();
            pstPlayBackCond.dwChannelID = NetDemo.ChannelID;
            pstPlayBackCond.hPlayWnd = Native.getComponentPointer(NetDemo.panelPlayLabel);
            pstPlayBackCond.tBeginTime = Common.date2TimeStamp(Beginstr, NetDemo.DateFormat);
            pstPlayBackCond.tEndTime = Common.date2TimeStamp(Endstr, NetDemo.DateFormat);
            pstPlayBackCond.dwLinkMode = NETDEV_TRANS_PROTOCAL_E.NETDEV_TRANS_PROTOCAL_TCP;
            NetDemo.lpPlayHandle=NetDemo.netdevsdk.NETDEV_PlayBackByUrl(NetDemo.lpUserID, pszReplayUrl, pstPlayBackCond);
            if(null != NetDemo.lpPlayHandle){
                NetDemo.jSliderPlayBack.setMaximum((int)pstPlayBackCond.tEndTime);
                NetDemo.jSliderPlayBack.setMinimum((int)pstPlayBackCond.tBeginTime);
                NetDemo.jSliderPlayBack.setValue(50);
                NetDemo.lblPlaybackSpeed.setText("1X");
                NetDemo.netdevsdk.NETDEV_SetMuteStatus(NetDemo.lpPlayHandle,1);
                NetDemo.netdevsdk.NETDEV_OpenSound(NetDemo.lpPlayHandle);
                Thread singlePlayBackByURLThread=new Thread(new Runnable() {
                    @Override
                    public void run() {
                        int nCount = 0;
                        while(true)
                        {
                            /* 获取窗口码率 */
                            IntByReference pdwBitRate = new IntByReference();
                            boolean bRetBit = NetDemo.netdevsdk.NETDEV_GetBitRate(NetDemo.lpPlayHandle,pdwBitRate);
                            if(bRetBit != true)
                            {
                                System.out.printf("NETDEV_GetBitRate failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                                return;
                            }
                            NetDemo.jLabelBitRateParam.setText(String.valueOf(pdwBitRate.getValue()));
                            
                            /* 获取窗口帧率 */
                            IntByReference pdwFrameRate = new IntByReference();
                            boolean bRet2 = NetDemo.netdevsdk.NETDEV_GetFrameRate(NetDemo.lpPlayHandle,pdwFrameRate);
                            if(bRet2 != true)
                            {
                                System.out.printf("NETDEV_GetFrameRate failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                                return;
                            }
                            NetDemo.jLabelFrameRate.setText(String.valueOf(pdwFrameRate.getValue()));
                            
                            /* 获取窗口编码格式 */
                            IntByReference pdwVideoEncFmt = new IntByReference();
                            boolean bRet3 = NetDemo.netdevsdk.NETDEV_GetVideoEncodeFmt(NetDemo.lpPlayHandle,pdwVideoEncFmt);
                            if(bRet3 != true)
                            {
                                System.out.printf("NETDEV_GetVideoEncodeFmt failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                                return;
                            }
                            String showEncodeFmt=null;
                            if(pdwVideoEncFmt.getValue()==NETDEV_VIDEO_CODE_TYPE_E.NETDEV_VIDEO_CODE_MJPEG){
                                showEncodeFmt="MJPEG";
                            }else if(pdwVideoEncFmt.getValue()==NETDEV_VIDEO_CODE_TYPE_E.NETDEV_VIDEO_CODE_H264) {
                                showEncodeFmt="H.264";
                            }else if(pdwVideoEncFmt.getValue()==NETDEV_VIDEO_CODE_TYPE_E.NETDEV_VIDEO_CODE_H265) {
                                showEncodeFmt="H.265";
                            }
                            NetDemo.jLabelVideoEncodeFmt.setText(showEncodeFmt);
                            
                            /* 获取视频分辨率 */
                            IntByReference pdwWidth = new IntByReference();
                            IntByReference pdwHeight = new IntByReference();
                            boolean bRet4 = NetDemo.netdevsdk.NETDEV_GetResolution(NetDemo.lpPlayHandle,pdwWidth,pdwHeight);
                            if(bRet4 != true)
                            {
                                System.out.printf("NETDEV_GetResolution failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                                return;
                            }
                            NetDemo.jLabelGetpdwWidth.setText(String.valueOf(pdwWidth.getValue())+"x");
                            NetDemo.jLabelGetpdwHeight.setText(String.valueOf(pdwHeight.getValue()));
 
 
                            /* 获取窗口丢包率 */
                            IntByReference pURLReceivePacketNum = new IntByReference();
                            IntByReference pURLLostPktNum = new IntByReference();
                            boolean bRet5 = NetDemo.netdevsdk.NETDEV_GetLostPacketRate(NetDemo.lpPlayHandle,pURLReceivePacketNum,pURLLostPktNum);
                            if(bRet5 != true)
                            {
                                System.out.printf("NETDEV_GetLostPacketRate failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                                return;
                            }
                            double lostPacketRate=0.0;
                            if(pURLLostPktNum.getValue()==0) {
                                lostPacketRate=0.0;
                            }else {
                                BigDecimal receive=new BigDecimal(pURLReceivePacketNum.getValue());
                                BigDecimal lost=new BigDecimal(pURLLostPktNum.getValue());
                                BigDecimal sum=receive.add(lost);
                                try {
                                    BigDecimal result=receive.divide(sum,2,BigDecimal.ROUND_HALF_UP);
                                    lostPacketRate=result.doubleValue();
                                } catch (Exception e) {                                  
                                    return;
                                }
                            }
                            NetDemo.jLabelGetpulRecvPktNum.setText(String.valueOf(lostPacketRate));
 
                            /* 获取静音状态 */
                            IntByReference pbMute=new IntByReference();
                            boolean bRet6= NetDemo.netdevsdk.NETDEV_GetMuteStatus(NetDemo.lpPlayHandle, pbMute);
                            if(!bRet6) {
                                System.out.printf("NETDEV_GetMuteStatus failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                                return;
                            }
                            NetDemo.getMute=pbMute.getValue();
                            
                            /* 控制录像回放的状态 */
                            LongByReference PlayTime = new LongByReference();
                            boolean bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_GETPLAYTIME, PlayTime);
                            if(bRet){
                                long lTime = PlayTime.getValue();
                                NetDemo.jSliderPlayBack.setValue((int)lTime);
                                long lRemainTime = (long)NetDemo.jSliderPlayBack.getMaximum() - lTime;
                                String strRemainTime = String.valueOf(lRemainTime/60/60) + ":" + String.valueOf((lRemainTime/60)%60) + ":"+ String.valueOf(lRemainTime%60);
                                String strInfo = Common.timeStamp2Date(String.valueOf(lTime), NetDemo.DateFormat);
                                strInfo += " / ";
                                strInfo += strRemainTime;
                                NetDemo.lblProgressLabel.setText(strInfo);
                                nCount = 0;
                            }
                            else{
                                nCount++;
                                System.out.println("Get playback time failed");
                            }
                            if((long)NetDemo.jSliderPlayBack.getMaximum() == PlayTime.getValue() || PlayTime.getValue() > (long)NetDemo.jSliderPlayBack.getMaximum()
                                    || nCount>3){
                                NetDemo.netdevsdk.NETDEV_StopPlayBack(NetDemo.lpPlayHandle);
                                NetDemo.lpPlayHandle = null;
                                break;
                            }
                            try{
                                Thread.sleep(700);
                            }catch(InterruptedException e){
                                e.printStackTrace();
                            }
                        }
 
                    }
                });
                NetDemo.singleLiveThread.execute(singlePlayBackByURLThread);
            }
        }else {
            System.out.println("NETDEV_GetReplayUrl, error:" + NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
 
    
        
    }
 
    /**
     * 
     * @introduction Playback by name
     * @description  Calling the interface of NETDEV_PlayBackByName
     *
     */
    public static void playByName() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0) {
            JOptionPane.showMessageDialog(null, "Please select an online channel.");
            return;
        }  
        if(NetDemo.RecordTable.getSelectedRow()<0) {
            JOptionPane.showMessageDialog(null, "No file,please choose a file");
            return;
        } 
        if(null != NetDemo.lpPlayHandle) {
            JOptionPane.showMessageDialog(null, "Please stop playing first.");
            return;
        }
        NetDemo.jButtonStopPlayback.setEnabled(true);
        NetDemo.jButtonMic.setVisible(false);
        NetDemo.jSliderLiveMicSound.setVisible(false);
        NetDemo.jLabelLiveSound2.setVisible(false);
        NetDemo.jLableLiveMicSound.setVisible(false);
        NetDemo.jLabelLiveViewStreamUrl.setText(null);
        NETDEV_PLAYBACKINFO_S pstPlayBackInfo = new NETDEV_PLAYBACKINFO_S();
 
        int row=NetDemo.RecordTable.getSelectedRow();
        /* 获取文件名 */
        String str=(String)NetDemo.RecordTable.getValueAt(row, 2);
        System.arraycopy(str.getBytes(), 0, pstPlayBackInfo.szName, 0, str.getBytes().length);
        String Beginstr=(String)NetDemo.RecordTable.getValueAt(row, 0);
        String Endstr=(String)NetDemo.RecordTable.getValueAt(row, 1);
        pstPlayBackInfo.tBeginTime =Common.date2TimeStamp(Beginstr, NetDemo.DateFormat);
        pstPlayBackInfo.tEndTime = Common.date2TimeStamp(Endstr, NetDemo.DateFormat);
        pstPlayBackInfo.dwLinkMode = NETDEV_TRANS_PROTOCAL_E.NETDEV_TRANS_PROTOCAL_TCP;
        pstPlayBackInfo.hPlayWnd = Native.getComponentPointer(NetDemo.panelPlayLabel);
        NetDemo.lpPlayHandle = NetDemo.netdevsdk.NETDEV_PlayBackByName(NetDemo.lpUserID, pstPlayBackInfo);
        if(null != NetDemo.lpPlayHandle){
            NetDemo.jSliderPlayBack.setMinimum((int)pstPlayBackInfo.tBeginTime);
            NetDemo.jSliderPlayBack.setMaximum((int)pstPlayBackInfo.tEndTime);
            NetDemo.jSliderPlayBack.setValue(50);
            NetDemo.lblPlaybackSpeed.setText("1X");
            NetDemo.netdevsdk.NETDEV_SetMuteStatus(NetDemo.lpPlayHandle,1);
            NetDemo.netdevsdk.NETDEV_OpenSound(NetDemo.lpPlayHandle);
            Thread singleRecordPlayByNameThread=new Thread(new Runnable() {
                @Override
                public void run() {
                    int nCount = 0;
                    while(true)
                    {
                        IntByReference pdwBitRate = new IntByReference();
                        boolean bRetBit = NetDemo.netdevsdk.NETDEV_GetBitRate(NetDemo.lpPlayHandle,pdwBitRate);
                        if(bRetBit != true)
                        {
                            System.out.printf("NETDEV_GetBitRate failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        NetDemo.jLabelBitRateParam.setText(String.valueOf(pdwBitRate.getValue()));
                        
                        IntByReference pdwFrameRate = new IntByReference();
                        boolean bRet2 = NetDemo.netdevsdk.NETDEV_GetFrameRate(NetDemo.lpPlayHandle,pdwFrameRate);
                        if(bRet2 != true)
                        {
                            System.out.printf("NETDEV_GetFrameRate failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        NetDemo.jLabelFrameRate.setText(String.valueOf(pdwFrameRate.getValue()));
                        
                        IntByReference pdwVideoEncFmt = new IntByReference();
                        boolean bRet3 = NetDemo.netdevsdk.NETDEV_GetVideoEncodeFmt(NetDemo.lpPlayHandle,pdwVideoEncFmt);
                        if(bRet3 != true)
                        {
                            System.out.printf("NETDEV_GetVideoEncodeFmt failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        String showEncodeFmt=null;
                        if(pdwVideoEncFmt.getValue()==NETDEV_VIDEO_CODE_TYPE_E.NETDEV_VIDEO_CODE_MJPEG){
                            showEncodeFmt="MJPEG";
                        }else if(pdwVideoEncFmt.getValue()==NETDEV_VIDEO_CODE_TYPE_E.NETDEV_VIDEO_CODE_H264) {
                            showEncodeFmt="H.264";
                        }else if(pdwVideoEncFmt.getValue()==NETDEV_VIDEO_CODE_TYPE_E.NETDEV_VIDEO_CODE_H265) {
                            showEncodeFmt="H.265";
                        }
                        NetDemo.jLabelVideoEncodeFmt.setText(showEncodeFmt);
                        
                        IntByReference pdwWidth = new IntByReference();
                        IntByReference pdwHeight = new IntByReference();
                        boolean bRet4 = NetDemo.netdevsdk.NETDEV_GetResolution(NetDemo.lpPlayHandle,pdwWidth,pdwHeight);
                        if(bRet4 != true)
                        {
                            System.out.printf("NETDEV_GetResolution failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        NetDemo.jLabelGetpdwWidth.setText(String.valueOf(pdwWidth.getValue())+"x");
                        NetDemo.jLabelGetpdwHeight.setText(String.valueOf(pdwHeight.getValue()));
                      
                        IntByReference pURLReceivePacketNum = new IntByReference();
                        IntByReference pURLLostPktNum = new IntByReference();
                        boolean bRet5 = NetDemo.netdevsdk.NETDEV_GetLostPacketRate(NetDemo.lpPlayHandle,pURLReceivePacketNum,pURLLostPktNum);
                        if(bRet5 != true)
                        {
                            System.out.printf("NETDEV_GetLostPacketRate failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        double lostPacketRate=0.0;
                        if(pURLLostPktNum.getValue()==0) {
                            lostPacketRate=0.0;
                        }else {
                            BigDecimal receive=new BigDecimal(pURLReceivePacketNum.getValue());
                            BigDecimal lost=new BigDecimal(pURLLostPktNum.getValue());
                            BigDecimal sum=receive.add(lost);
                            try {
                                BigDecimal result=receive.divide(sum,2,BigDecimal.ROUND_HALF_UP);
                                lostPacketRate=result.doubleValue();
                            } catch (Exception e) {                                  
                                return;
                            }
                        }
                        NetDemo.jLabelGetpulRecvPktNum.setText(String.valueOf(lostPacketRate));
 
                        IntByReference pbMute=new IntByReference();
                        boolean bRet6= NetDemo.netdevsdk.NETDEV_GetMuteStatus(NetDemo.lpPlayHandle, pbMute);
                        if(!bRet6) {
                            System.out.printf("NETDEV_GetMuteStatus failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        NetDemo.getMute=pbMute.getValue();
                        LongByReference PlayTime = new LongByReference();
                        boolean bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_GETPLAYTIME, PlayTime);
                        if(bRet){
                            long lTime = PlayTime.getValue();
                            NetDemo.jSliderPlayBack.setValue((int)lTime);
                            long lRemainTime = (long)NetDemo.jSliderPlayBack.getMaximum() - lTime;
 
                            String strRemainTime = String.valueOf(lRemainTime/60/60) + ":" + String.valueOf((lRemainTime/60)%60) + ":"+ String.valueOf(lRemainTime%60);
 
                            String strInfo = Common.timeStamp2Date(String.valueOf(lTime), NetDemo.DateFormat);
                            strInfo += " / ";
                            strInfo += strRemainTime;
                            NetDemo.lblProgressLabel.setText(strInfo);
                            nCount = 0;
                        }
                        else{
                            nCount++;
                            System.out.println("Get playback time failed");
                        }
                        if((long)NetDemo.jSliderPlayBack.getMaximum() == PlayTime.getValue() || PlayTime.getValue() > (long)NetDemo.jSliderPlayBack.getMaximum()
                                || nCount>3){
                            NetDemo.netdevsdk.NETDEV_StopPlayBack(NetDemo.lpPlayHandle);
                            NetDemo.lpPlayHandle = null;
                            break;
                        }
                        try{
                            Thread.sleep(700);
                        }catch(InterruptedException e){
                            e.printStackTrace();
                        }
                    }
                }
            });
            NetDemo.singleLiveThread.execute(singleRecordPlayByNameThread);
        }
    }
 
    /**
     * 
     * @introduction Playback by time
     * @description Calling the interface of NETDEV_PlayBackByTime
     *
     */
    public static void playByTime() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0) {
            JOptionPane.showMessageDialog(null, "Please select an online channel.");
            return;
        }
        if(null != NetDemo.lpPlayHandle) {
            JOptionPane.showMessageDialog(null, "Please stop playing first.");
            return;
        }
        if(NetDemo.RecordTable.getSelectedRow()<0) {
            JOptionPane.showMessageDialog(null, "No file,please choose a file");
            return;
        } 
        NetDemo.jButtonStopPlayback.setEnabled(true);
        NetDemo.jButtonMic.setVisible(false);
        NetDemo.jSliderLiveMicSound.setVisible(false);
        NetDemo.jLabelLiveSound2.setVisible(false);
        NetDemo.jLableLiveMicSound.setVisible(false);
        NetDemo.jLabelLiveViewStreamUrl.setText(null);
        
      //获取选中行
        int row=NetDemo.RecordTable.getSelectedRow(); 
        String Beginstr=(String)NetDemo.RecordTable.getValueAt(row, 0);
        String Endstr=(String)NetDemo.RecordTable.getValueAt(row, 1);
        
        NETDEV_PLAYBACKCOND_S pstPlayBackInfo = new NETDEV_PLAYBACKCOND_S();
        pstPlayBackInfo.dwChannelID = NetDemo.ChannelID;
        pstPlayBackInfo.hPlayWnd = Native.getComponentPointer(NetDemo.panelPlayLabel);
        pstPlayBackInfo.tBeginTime = Common.date2TimeStamp(Beginstr, NetDemo.DateFormat);
        pstPlayBackInfo.tEndTime = Common.date2TimeStamp(Endstr, NetDemo.DateFormat);
        pstPlayBackInfo.dwLinkMode = NETDEV_TRANS_PROTOCAL_E.NETDEV_TRANS_PROTOCAL_TCP;
        
        NetDemo.lpPlayHandle = NetDemo.netdevsdk.NETDEV_PlayBackByTime(NetDemo.lpUserID, pstPlayBackInfo);
        if(null != NetDemo.lpPlayHandle){
            NetDemo.jSliderPlayBack.setMaximum((int)pstPlayBackInfo.tEndTime);
            NetDemo.jSliderPlayBack.setMinimum((int)pstPlayBackInfo.tBeginTime);
            NetDemo.jSliderPlayBack.setValue(50);
            NetDemo.lblPlaybackSpeed.setText("1X");
            NetDemo.netdevsdk.NETDEV_SetMuteStatus(NetDemo.lpPlayHandle,1);
            NetDemo.netdevsdk.NETDEV_OpenSound(NetDemo.lpPlayHandle);
               
            Thread singleRecordPlayThread=new Thread(new Runnable() {
                @Override
                public void run() {
                    int nCount = 0;
                    while(null!=NetDemo.lpPlayHandle) {
                        IntByReference pdwBitRate = new IntByReference();
                        boolean bRetBit = NetDemo.netdevsdk.NETDEV_GetBitRate(NetDemo.lpPlayHandle,pdwBitRate);
                        if(bRetBit != true) {
                            System.out.printf("NETDEV_GetBitRate failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        NetDemo.jLabelBitRateParam.setText(String.valueOf(pdwBitRate.getValue()));
                        
                        IntByReference pdwFrameRate = new IntByReference();
                        boolean bRet2 = NetDemo.netdevsdk.NETDEV_GetFrameRate(NetDemo.lpPlayHandle,pdwFrameRate);
                        if(bRet2 != true)
                        {
                            System.out.printf("NETDEV_GetFrameRate failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        NetDemo.jLabelFrameRate.setText(String.valueOf(pdwFrameRate.getValue()));
                        
                        IntByReference pdwVideoEncFmt = new IntByReference();
                        boolean bRet3 = NetDemo.netdevsdk.NETDEV_GetVideoEncodeFmt(NetDemo.lpPlayHandle,pdwVideoEncFmt);
                        if(bRet3 != true)
                        {
                            System.out.printf("NETDEV_GetVideoEncodeFmt failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        String showEncodeFmt=null;
                        if(pdwVideoEncFmt.getValue()==NETDEV_VIDEO_CODE_TYPE_E.NETDEV_VIDEO_CODE_MJPEG){
                            showEncodeFmt="MJPEG";
                        }else if(pdwVideoEncFmt.getValue()==NETDEV_VIDEO_CODE_TYPE_E.NETDEV_VIDEO_CODE_H264) {
                            showEncodeFmt="H.264";
                        }else if(pdwVideoEncFmt.getValue()==NETDEV_VIDEO_CODE_TYPE_E.NETDEV_VIDEO_CODE_H265) {
                            showEncodeFmt="H.265";
                        }
                        NetDemo.jLabelVideoEncodeFmt.setText(showEncodeFmt);
                        
                        IntByReference pdwWidth = new IntByReference();
                        IntByReference pdwHeight = new IntByReference();
                        boolean bRet4 = NetDemo.netdevsdk.NETDEV_GetResolution(NetDemo.lpPlayHandle,pdwWidth,pdwHeight);
                        if(bRet4 != true)
                        {
                            System.out.printf("NETDEV_GetResolution failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        NetDemo.jLabelGetpdwWidth.setText(String.valueOf(pdwWidth.getValue())+"x");
                        NetDemo.jLabelGetpdwHeight.setText(String.valueOf(pdwHeight.getValue()));
                        
                        IntByReference pURLReceivePacketNum = new IntByReference();
                        IntByReference pURLLostPktNum = new IntByReference();
                        boolean bRet5 = NetDemo.netdevsdk.NETDEV_GetLostPacketRate(NetDemo.lpPlayHandle,pURLReceivePacketNum,pURLLostPktNum);
                        if(bRet5 != true)
                        {
                            System.out.printf("NETDEV_GetLostPacketRate failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        double lostPacketRate=0.0;
                        if(pURLLostPktNum.getValue()==0) {
                            lostPacketRate=0.0;
                        }else {
                            BigDecimal receive=new BigDecimal(pURLReceivePacketNum.getValue());
                            BigDecimal lost=new BigDecimal(pURLLostPktNum.getValue());
                            BigDecimal sum=receive.add(lost);
                            try {
                                BigDecimal result=receive.divide(sum,2,BigDecimal.ROUND_HALF_UP);
                                lostPacketRate=result.doubleValue();
                            } catch (Exception e) {                                  
                                return;
                            }
                        }
                        NetDemo.jLabelGetpulRecvPktNum.setText(String.valueOf(lostPacketRate));
 
                        IntByReference pbMute=new IntByReference();
                        boolean bRet6= NetDemo.netdevsdk.NETDEV_GetMuteStatus(NetDemo.lpPlayHandle, pbMute);
                        if(!bRet6) {
                            System.out.printf("NETDEV_GetMuteStatus failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                            return;
                        }
                        NetDemo.getMute=pbMute.getValue();
                        LongByReference PlayTime = new LongByReference();
                        boolean bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_GETPLAYTIME, PlayTime);
                        if(bRet){
                            long lTime = PlayTime.getValue(); 
                            NetDemo.jSliderPlayBack.setValue((int)lTime);
                            long lRemainTime = (long)NetDemo.jSliderPlayBack.getMaximum() - lTime;
                            String strRemainTime = String.valueOf(lRemainTime/60/60) + ":" + String.valueOf((lRemainTime/60)%60) + ":"+ String.valueOf(lRemainTime%60);
                            String strInfo = Common.timeStamp2Date(String.valueOf(lTime), NetDemo.DateFormat);
                            strInfo += " / ";
                            strInfo += strRemainTime;
                            NetDemo.lblProgressLabel.setText(strInfo);
                            nCount = 0;
                        }
                        else{
                            nCount++;
                            System.out.println("Get playback time failed");
                        }
                        if((long)NetDemo.jSliderPlayBack.getMaximum() == PlayTime.getValue() || PlayTime.getValue() > (long)NetDemo.jSliderPlayBack.getMaximum()
                                || nCount>3){
                            NetDemo.netdevsdk.NETDEV_StopPlayBack(NetDemo.lpPlayHandle);
                            NetDemo.lpPlayHandle = null;
                            break;
                        }
                        try{
                            Thread.sleep(700);
                            }catch(InterruptedException e){
                            e.printStackTrace();
                            }
                        }
                    }
                });
            NetDemo.singleLiveThread.execute(singleRecordPlayThread);
            }    
        }
 
    /**
     * 
     * @introduction Stop playback
     * @description Calling the interface of NETDEV_StopPlayBack
     *
     */
    public static void stopPlay() {
        if(null != NetDemo.lpPlayHandle){
            NetDemo.netdevsdk.NETDEV_StopPlayBack(NetDemo.lpPlayHandle);
            NetDemo.lpPlayHandle = null;
        }
        NetDemo.jButtonStopPlayback.setEnabled(false);
        NetDemo.panelPlayLabel.repaint();
        NetDemo.jSliderPlayBack.setValue(0);
        NetDemo.jButtonMic.setVisible(true);
        NetDemo.jSliderLiveMicSound.setVisible(true);
        NetDemo.jLabelFrameRate.setText(null);
        NetDemo.jLabelBitRateParam.setText(null);
        NetDemo.jLabelVideoEncodeFmt.setText(null);
        NetDemo.jLabelGetpdwWidth.setText(null);
        NetDemo.jLabelGetpdwHeight.setText(null);
        NetDemo.jLabelGetpulRecvPktNum.setText(null);
        NetDemo.jLabelLiveViewStreamUrl.setText(null);
        NetDemo.lblProgressLabel.setText(null);
        NetDemo.lblPlaybackSpeed.setText("1X");
    }
 
    /**
     * 
     * @introduction Pause or Resume
     * @description Calling the interface of NETDEV_PlayBackControl
     *
     */
    public static void pauseOrResume() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_PAUSE == NetDemo.PlayBackControlCmd){
            boolean bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_RESUME, null);
            if(bRet){
                NetDemo.PlayBackControlCmd = NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_RESUME;
                NetDemo.jButtonPauseOrResume.setText("pause");
            }
        }
        else{
            boolean bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_PAUSE, null);
            if(bRet){
                NetDemo.PlayBackControlCmd = NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_PAUSE;
                NetDemo.jButtonPauseOrResume.setText("Resume");
            }
        }
    }
 
    /**
     * 
     * @introduction  Drag playback progress bar to change play time 
     * @description
     *
     */
    public static void dragPlaybackSlider() {
        /* 保持拖动进度条前后播放状态相同 */
        if(NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_PAUSE == NetDemo.PlayBackControlCmd) {
            LongByReference PlayTime = new LongByReference();
            PlayTime.setValue((long)NetDemo.jSliderPlayBack.getValue());
            boolean bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_SETPLAYTIME, PlayTime);      
            if(!bRet){
                System.out.println("Set playback time failed:" + Common.timeStamp2Date(Long.toString(PlayTime.getValue()), NetDemo.DateFormat));
            }
            boolean bRet1 = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_PAUSE, null);
            if(bRet1){
                NetDemo.PlayBackControlCmd = NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_PAUSE;
                NetDemo.jButtonPauseOrResume.setText("Resume");
            }
        }else {
            LongByReference PlayTime = new LongByReference();
            PlayTime.setValue((long)NetDemo.jSliderPlayBack.getValue());
            boolean bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_SETPLAYTIME, PlayTime);      
            if(!bRet){
                System.out.println("Set playback time failed:" + Common.timeStamp2Date(Long.toString(PlayTime.getValue()), NetDemo.DateFormat));
            }
        }
    }
 
    /**
     * 
     * @introduction Slow the speed of playing playback
     * @description Calling the interface of NETDEV_PlayBackControl
     *
     */
    public static void slowPlaySpeed() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        LongByReference PlaySpeed = new LongByReference();
        boolean bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_GETPLAYSPEED, PlaySpeed);
        if(!bRet){
            System.out.println("Get playback speed failed");
            return;
        }
        long value = PlaySpeed.getValue();
        if(value <= NETDEV_VOD_PLAY_STATUS_E.NETDEV_PLAY_STATUS_16_BACKWARD){
            JOptionPane.showMessageDialog(null, "It's already minimum playback speed.");
            return;
        }
        value -= 1;
        if((value==NETDEV_VOD_PLAY_STATUS_E.NETDEV_PLAY_STATUS_HALF_BACKWARD)||(value==NETDEV_VOD_PLAY_STATUS_E.NETDEV_PLAY_STATUS_QUARTER_BACKWARD)) {
            value-=2;
        }
        PlaySpeed.setValue(value);
         bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_SETPLAYSPEED, PlaySpeed);
        if(!bRet){
            System.out.println("Set playback speed failed:" + value);
        }
        else{
            NetDemo.lblPlaybackSpeed.setText(Common.PlaybackSpeedToLong((int)value));
            System.out.println("Set playback speed success:" + value);
        }
        if(NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_PAUSE == NetDemo.PlayBackControlCmd) {
            NetDemo.jButtonPauseOrResume.doClick();
        }
    }
    
    /**
     * 
     * @introduction Fast the speed of playing playback
     * @description  Calling the interface of NETDEV_PlayBackControl
     *
     */
    public static void fastPlaySpeed() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        LongByReference PlaySpeed = new LongByReference();
        boolean bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_GETPLAYSPEED, PlaySpeed);
        if(!bRet){
            System.out.println("Get playback speed failed");
            return;
        }
        long value = PlaySpeed.getValue();
        if(value >= NETDEV_VOD_PLAY_STATUS_E.NETDEV_PLAY_STATUS_16_FORWARD){
            JOptionPane.showMessageDialog(null, "It's already maximum playback speed.");
            return;
        }
        value += 1;
        if((value==NETDEV_VOD_PLAY_STATUS_E.NETDEV_PLAY_STATUS_HALF_BACKWARD)||(value==NETDEV_VOD_PLAY_STATUS_E.NETDEV_PLAY_STATUS_QUARTER_BACKWARD)) {
            value+=2;
        }
        PlaySpeed.setValue(value);
         bRet = NetDemo.netdevsdk.NETDEV_PlayBackControl(NetDemo.lpPlayHandle, NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_SETPLAYSPEED, PlaySpeed);
        if(!bRet){
            System.out.println("Set playback speed failed:" + value);
        }
        else{
            NetDemo.lblPlaybackSpeed.setText(Common.PlaybackSpeedToLong((int)value));
            System.out.println("Set playback speed success:" + value);
        }
        if(NETDEV_VOD_PLAY_CTRL_E.NETDEV_PLAY_CTRL_PAUSE == NetDemo.PlayBackControlCmd) {
            NetDemo.jButtonPauseOrResume.doClick();
        }
    }
 
}