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 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
|
///////////////////////////////////////////////////////////////////////////////
// Name: mediaplayer.cpp
// Purpose: wxMediaCtrl sample
// Author: Ryan Norton
// Modified by:
// Created: 11/10/04
// Copyright: (c) Ryan Norton
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// MediaPlayer
//
// This is a somewhat comprehensive example of how to use all the funtionality
// of the wxMediaCtrl class in wxWidgets.
//
// To use this sample, simply select Open File from the file menu,
// select the file you want to play - and MediaPlayer will play the file in a
// the current notebook page, showing video if necessary.
//
// You can select one of the menu options, or move the slider around
// to manipulate what is playing.
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Known bugs with wxMediaCtrl:
//
// 1) Certain backends can't play the same media file at the same time (MCI,
// Cocoa NSMovieView-Quicktime).
// 2) Positioning on Mac Carbon is messed up if put in a sub-control like a
// Notebook (like this sample does).
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// ============================================================================
// Definitions
// ============================================================================
// ----------------------------------------------------------------------------
// Pre-compiled header stuff
// ----------------------------------------------------------------------------
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// ----------------------------------------------------------------------------
// Headers
// ----------------------------------------------------------------------------
#include "wx/mediactrl.h" // for wxMediaCtrl
#include "wx/filedlg.h" // for opening files from OpenFile
#include "wx/slider.h" // for a slider for seeking within media
#include "wx/sizer.h" // for positioning controls/wxBoxSizer
#include "wx/timer.h" // timer for updating status bar
#include "wx/textdlg.h" // for getting user text from OpenURL/Debug
#include "wx/notebook.h" // for wxNotebook and putting movies in pages
#include "wx/cmdline.h" // for wxCmdLineParser (optional)
#include "wx/listctrl.h" // for wxListCtrl
#include "wx/dnd.h" // drag and drop for the playlist
#include "wx/filename.h" // For wxFileName::GetName()
#include "wx/config.h" // for native wxConfig
#include "wx/vector.h"
// Under MSW we have several different backends but when linking statically
// they may be discarded by the linker (this definitely happens with MSVC) so
// force linking them. You don't have to do this in your code if you don't plan
// to use them, of course.
#if defined(__WXMSW__) && !defined(WXUSINGDLL)
#include "wx/link.h"
wxFORCE_LINK_MODULE(wxmediabackend_am)
wxFORCE_LINK_MODULE(wxmediabackend_qt)
wxFORCE_LINK_MODULE(wxmediabackend_wmp10)
#endif // static wxMSW build
#ifndef wxHAS_IMAGES_IN_RESOURCES
#include "../sample.xpm"
#endif
// ----------------------------------------------------------------------------
// Bail out if the user doesn't want one of the
// things we need
// ----------------------------------------------------------------------------
#if !wxUSE_MEDIACTRL || !wxUSE_MENUS || !wxUSE_SLIDER || !wxUSE_TIMER || \
!wxUSE_NOTEBOOK || !wxUSE_LISTCTRL
#error "Not all required elements are enabled. Please modify setup.h!"
#endif
// ============================================================================
// Declarations
// ============================================================================
// ----------------------------------------------------------------------------
// Enumurations
// ----------------------------------------------------------------------------
// IDs for the controls and the menu commands
enum
{
// Menu event IDs
wxID_LOOP = 1,
wxID_OPENFILESAMEPAGE,
wxID_OPENFILENEWPAGE,
wxID_OPENURLSAMEPAGE,
wxID_OPENURLNEWPAGE,
wxID_CLOSECURRENTPAGE,
wxID_PLAY,
wxID_PAUSE,
wxID_NEXT,
wxID_PREV,
wxID_SELECTBACKEND,
wxID_SHOWINTERFACE,
// wxID_STOP, [built-in to wxWidgets]
// wxID_ABOUT, [built-in to wxWidgets]
// wxID_EXIT, [built-in to wxWidgets]
// Control event IDs
wxID_SLIDER,
wxID_PBSLIDER,
wxID_VOLSLIDER,
wxID_NOTEBOOK,
wxID_MEDIACTRL,
wxID_BUTTONNEXT,
wxID_BUTTONPREV,
wxID_BUTTONSTOP,
wxID_BUTTONPLAY,
wxID_BUTTONVD,
wxID_BUTTONVU,
wxID_LISTCTRL,
wxID_GAUGE
};
// ----------------------------------------------------------------------------
// wxMediaPlayerApp
// ----------------------------------------------------------------------------
class wxMediaPlayerApp : public wxApp
{
public:
#ifdef __WXMAC__
virtual void MacOpenFiles(const wxArrayString & fileNames );
#endif
#if wxUSE_CMDLINE_PARSER
virtual void OnInitCmdLine(wxCmdLineParser& parser);
virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
// Files specified on the command line, if any.
wxVector<wxString> m_params;
#endif // wxUSE_CMDLINE_PARSER
virtual bool OnInit();
protected:
class wxMediaPlayerFrame* m_frame;
};
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame
// ----------------------------------------------------------------------------
class wxMediaPlayerFrame : public wxFrame
{
public:
// Ctor/Dtor
wxMediaPlayerFrame(const wxString& title);
~wxMediaPlayerFrame();
// Menu event handlers
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnOpenFileSamePage(wxCommandEvent& event);
void OnOpenFileNewPage(wxCommandEvent& event);
void OnOpenURLSamePage(wxCommandEvent& event);
void OnOpenURLNewPage(wxCommandEvent& event);
void OnCloseCurrentPage(wxCommandEvent& event);
void OnPlay(wxCommandEvent& event);
void OnPause(wxCommandEvent& event);
void OnStop(wxCommandEvent& event);
void OnNext(wxCommandEvent& event);
void OnPrev(wxCommandEvent& event);
void OnVolumeDown(wxCommandEvent& event);
void OnVolumeUp(wxCommandEvent& event);
void OnLoop(wxCommandEvent& event);
void OnShowInterface(wxCommandEvent& event);
void OnSelectBackend(wxCommandEvent& event);
// Key event handlers
void OnKeyDown(wxKeyEvent& event);
// Quickie for playing from command line
void AddToPlayList(const wxString& szString);
// ListCtrl event handlers
void OnChangeSong(wxListEvent& event);
// Media event handlers
void OnMediaLoaded(wxMediaEvent& event);
// Close event handlers
void OnClose(wxCloseEvent& event);
private:
// Common open file code
void OpenFile(bool bNewPage);
void OpenURL(bool bNewPage);
void DoOpenFile(const wxString& path, bool bNewPage);
void DoPlayFile(const wxString& path);
class wxMediaPlayerTimer* m_timer; // Timer to write info to status bar
wxNotebook* m_notebook; // Notebook containing our pages
// Maybe I should use more accessors, but for simplicity
// I'll allow the other classes access to our members
friend class wxMediaPlayerApp;
friend class wxMediaPlayerNotebookPage;
friend class wxMediaPlayerTimer;
};
// ----------------------------------------------------------------------------
// wxMediaPlayerNotebookPage
// ----------------------------------------------------------------------------
class wxMediaPlayerNotebookPage : public wxPanel
{
wxMediaPlayerNotebookPage(wxMediaPlayerFrame* parentFrame,
wxNotebook* book, const wxString& be = wxEmptyString);
// Slider event handlers
void OnBeginSeek(wxScrollEvent& event);
void OnEndSeek(wxScrollEvent& event);
void OnPBChange(wxScrollEvent& event);
void OnVolChange(wxScrollEvent& event);
// Media event handlers
void OnMediaPlay(wxMediaEvent& event);
void OnMediaPause(wxMediaEvent& event);
void OnMediaStop(wxMediaEvent& event);
void OnMediaFinished(wxMediaEvent& event);
public:
bool IsBeingDragged(); // accessor for m_bIsBeingDragged
// make wxMediaPlayerFrame able to access the private members
friend class wxMediaPlayerFrame;
int m_nLastFileId; // List ID of played file in listctrl
wxString m_szFile; // Name of currently playing file/location
wxMediaCtrl* m_mediactrl; // Our media control
class wxMediaPlayerListCtrl* m_playlist; // Our playlist
wxSlider* m_slider; // The slider below our media control
wxSlider* m_pbSlider; // Lower-left slider for adjusting speed
wxSlider* m_volSlider; // Lower-right slider for adjusting volume
int m_nLoops; // Number of times media has looped
bool m_bLoop; // Whether we are looping or not
bool m_bIsBeingDragged; // Whether the user is dragging the scroll bar
wxMediaPlayerFrame* m_parentFrame; // Main wxFrame of our sample
wxButton* m_prevButton; // Go to previous file button
wxButton* m_playButton; // Play/pause file button
wxButton* m_stopButton; // Stop playing file button
wxButton* m_nextButton; // Next file button
wxButton* m_vdButton; // Volume down button
wxButton* m_vuButton; // Volume up button
wxGauge* m_gauge; // Gauge to keep in line with slider
};
// ----------------------------------------------------------------------------
// wxMediaPlayerTimer
// ----------------------------------------------------------------------------
class wxMediaPlayerTimer : public wxTimer
{
public:
// Ctor
wxMediaPlayerTimer(wxMediaPlayerFrame* frame) {m_frame = frame;}
// Called each time the timer's timeout expires
void Notify();
wxMediaPlayerFrame* m_frame; // The wxMediaPlayerFrame
};
// ----------------------------------------------------------------------------
// wxMediaPlayerListCtrl
// ----------------------------------------------------------------------------
class wxMediaPlayerListCtrl : public wxListCtrl
{
public:
void AddToPlayList(const wxString& szString)
{
wxListItem kNewItem;
kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
int nID = this->GetItemCount();
kNewItem.SetId(nID);
kNewItem.SetMask(wxLIST_MASK_DATA);
kNewItem.SetData(new wxString(szString));
this->InsertItem(kNewItem);
this->SetItem(nID, 0, wxT("*"));
this->SetItem(nID, 1, wxFileName(szString).GetName());
if (nID % 2)
{
kNewItem.SetBackgroundColour(wxColour(192,192,192));
this->SetItem(kNewItem);
}
}
void GetSelectedItem(wxListItem& listitem)
{
listitem.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_DATA);
int nLast = -1, nLastSelected = -1;
while ((nLast = this->GetNextItem(nLast,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) != -1)
{
listitem.SetId(nLast);
this->GetItem(listitem);
if ((listitem.GetState() & wxLIST_STATE_FOCUSED) )
break;
nLastSelected = nLast;
}
if (nLast == -1 && nLastSelected == -1)
return;
listitem.SetId(nLastSelected == -1 ? nLast : nLastSelected);
this->GetItem(listitem);
}
};
// ----------------------------------------------------------------------------
// wxPlayListDropTarget
//
// Drop target for playlist (i.e. allows users to drag a file from explorer into
// the playlist to add that file)
// ----------------------------------------------------------------------------
#if wxUSE_DRAG_AND_DROP
class wxPlayListDropTarget : public wxFileDropTarget
{
public:
wxPlayListDropTarget(wxMediaPlayerListCtrl& list) : m_list(list) {}
~wxPlayListDropTarget(){}
virtual bool OnDropFiles(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
const wxArrayString& files)
{
for (size_t i = 0; i < files.GetCount(); ++i)
{
m_list.AddToPlayList(files[i]);
}
return true;
}
wxMediaPlayerListCtrl& m_list;
};
#endif
// ============================================================================
//
// Implementation
//
// ============================================================================
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// [Functions]
//
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ----------------------------------------------------------------------------
// wxGetMediaStateText
//
// Converts a wxMediaCtrl state into something useful that we can display
// to the user
// ----------------------------------------------------------------------------
const wxChar* wxGetMediaStateText(int nState)
{
switch(nState)
{
case wxMEDIASTATE_PLAYING:
return wxT("Playing");
case wxMEDIASTATE_STOPPED:
return wxT("Stopped");
///case wxMEDIASTATE_PAUSED:
default:
return wxT("Paused");
}
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// wxMediaPlayerApp
//
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ----------------------------------------------------------------------------
// This sets up this wxApp as the global wxApp that gui calls in wxWidgets
// use. For example, if you were to be in windows and use a file dialog,
// wxWidgets would use wxTheApp->GetHInstance() which would get the instance
// handle of the application. These routines in wx _DO NOT_ check to see if
// the wxApp exists, and thus will crash the application if you try it.
//
// IMPLEMENT_APP does this, and also implements the platform-specific entry
// routine, such as main or WinMain(). Use IMPLEMENT_APP_NO_MAIN if you do
// not desire this behaviour.
// ----------------------------------------------------------------------------
IMPLEMENT_APP(wxMediaPlayerApp)
// ----------------------------------------------------------------------------
// wxMediaPlayerApp command line parsing
// ----------------------------------------------------------------------------
#if wxUSE_CMDLINE_PARSER
void wxMediaPlayerApp::OnInitCmdLine(wxCmdLineParser& parser)
{
wxApp::OnInitCmdLine(parser);
parser.AddParam("input files",
wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE);
}
bool wxMediaPlayerApp::OnCmdLineParsed(wxCmdLineParser& parser)
{
if ( !wxApp::OnCmdLineParsed(parser) )
return false;
for (size_t paramNr=0; paramNr < parser.GetParamCount(); ++paramNr)
m_params.push_back(parser.GetParam(paramNr));
return true;
}
#endif // wxUSE_CMDLINE_PARSER
// ----------------------------------------------------------------------------
// wxMediaPlayerApp::OnInit
//
// Where execution starts - akin to a main or WinMain.
// 1) Create the frame and show it to the user
// 2) Process filenames from the commandline
// 3) return true specifying that we want execution to continue past OnInit
// ----------------------------------------------------------------------------
bool wxMediaPlayerApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
// SetAppName() lets wxConfig and others know where to write
SetAppName(wxT("wxMediaPlayer"));
wxMediaPlayerFrame *frame =
new wxMediaPlayerFrame(wxT("MediaPlayer wxWidgets Sample"));
frame->Show(true);
#if wxUSE_CMDLINE_PARSER
if ( !m_params.empty() )
{
for ( size_t n = 0; n < m_params.size(); n++ )
frame->AddToPlayList(m_params[n]);
wxCommandEvent theEvent(wxEVT_MENU, wxID_NEXT);
frame->AddPendingEvent(theEvent);
}
#endif // wxUSE_CMDLINE_PARSER
return true;
}
#ifdef __WXMAC__
void wxMediaPlayerApp::MacOpenFiles(const wxArrayString & fileNames )
{
// Called when a user drags files over our app
m_frame->DoOpenFile(fileNames[0], true /* new page */);
}
#endif // __WXMAC__
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// wxMediaPlayerFrame
//
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame Constructor
//
// 1) Create our menus
// 2) Create our notebook control and add it to the frame
// 3) Create our status bar
// 4) Connect our events
// 5) Start our timer
// ----------------------------------------------------------------------------
wxMediaPlayerFrame::wxMediaPlayerFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600,600))
{
SetIcon(wxICON(sample));
//
// Create Menus
//
wxMenu *fileMenu = new wxMenu;
wxMenu *controlsMenu = new wxMenu;
wxMenu *optionsMenu = new wxMenu;
wxMenu *helpMenu = new wxMenu;
wxMenu *debugMenu = new wxMenu;
fileMenu->Append(wxID_OPENFILESAMEPAGE, wxT("&Open File\tCtrl-Shift-O"),
wxT("Open a File in the current notebook page"));
fileMenu->Append(wxID_OPENFILENEWPAGE, wxT("&Open File in a new page"),
wxT("Open a File in a new notebook page"));
fileMenu->Append(wxID_OPENURLSAMEPAGE, wxT("&Open URL"),
wxT("Open a URL in the current notebook page"));
fileMenu->Append(wxID_OPENURLNEWPAGE, wxT("&Open URL in a new page"),
wxT("Open a URL in a new notebook page"));
fileMenu->AppendSeparator();
fileMenu->Append(wxID_CLOSECURRENTPAGE, wxT("&Close Current Page\tCtrl-C"),
wxT("Close current notebook page"));
fileMenu->AppendSeparator();
fileMenu->Append(wxID_EXIT,
wxT("E&xit\tAlt-X"),
wxT("Quit this program"));
controlsMenu->Append(wxID_PLAY, wxT("&Play/Pause\tCtrl-P"), wxT("Resume/Pause playback"));
controlsMenu->Append(wxID_STOP, wxT("&Stop\tCtrl-S"), wxT("Stop playback"));
controlsMenu->AppendSeparator();
controlsMenu->Append(wxID_PREV, wxT("&Previous\tCtrl-B"), wxT("Go to previous track"));
controlsMenu->Append(wxID_NEXT, wxT("&Next\tCtrl-N"), wxT("Skip to next track"));
optionsMenu->AppendCheckItem(wxID_LOOP,
wxT("&Loop\tCtrl-L"),
wxT("Loop Selected Media"));
optionsMenu->AppendCheckItem(wxID_SHOWINTERFACE,
wxT("&Show Interface\tCtrl-I"),
wxT("Show wxMediaCtrl native controls"));
debugMenu->Append(wxID_SELECTBACKEND,
wxT("&Select Backend...\tCtrl-D"),
wxT("Select a backend manually"));
helpMenu->Append(wxID_ABOUT,
wxT("&About\tF1"),
wxT("Show about dialog"));
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, wxT("&File"));
menuBar->Append(controlsMenu, wxT("&Controls"));
menuBar->Append(optionsMenu, wxT("&Options"));
menuBar->Append(debugMenu, wxT("&Debug"));
menuBar->Append(helpMenu, wxT("&Help"));
SetMenuBar(menuBar);
//
// Create our notebook - using wxNotebook is luckily pretty
// simple and self-explanatory in most cases
//
m_notebook = new wxNotebook(this, wxID_NOTEBOOK);
//
// Create our status bar
//
#if wxUSE_STATUSBAR
// create a status bar just for fun (by default with 1 pane only)
CreateStatusBar(1);
#endif // wxUSE_STATUSBAR
//
// Connect events.
//
// There are two ways in wxWidgets to use events -
// Message Maps and Connections.
//
// Message Maps are implemented by putting
// DECLARE_MESSAGE_MAP in your wxEvtHandler-derived
// class you want to use for events, such as wxMediaPlayerFrame.
//
// Then after your class declaration you put
// wxBEGIN_EVENT_TABLE(wxMediaPlayerFrame, wxFrame)
// EVT_XXX(XXX)...
// wxEND_EVENT_TABLE()
//
// Where wxMediaPlayerFrame is the class with the DECLARE_MESSAGE_MAP
// in it. EVT_XXX(XXX) are each of your handlers, such
// as EVT_MENU for menu events and the XXX inside
// is the parameters to the event macro - in the case
// of EVT_MENU the menu id and then the function to call.
//
// However, with wxEvtHandler::Connect you can avoid a
// global message map for your class and those annoying
// macros. You can also change the context in which
// the call the handler (more later).
//
// The downside is that due to the limitation that
// wxWidgets doesn't use templates in certain areas,
// You have to triple-cast the event function.
//
// There are five parameters to wxEvtHandler::Connect -
//
// The first is the id of the instance whose events
// you want to handle - i.e. a menu id for menus,
// a control id for controls (wxControl::GetId())
// and so on.
//
// The second is the event id. This is the same
// as the message maps (EVT_MENU) except prefixed
// with "wx" (wxEVT_MENU).
//
// The third is the function handler for the event -
// You need to cast it to the specific event handler
// type, then to a wxEventFunction, then to a
// wxObjectEventFunction - I.E.
// (wxObjectEventFunction)(wxEventFunction)
// (wxCommandEventFunction) &wxMediaPlayerFrame::MyHandler
//
// Or, you can use the new (2.5.5+) event handler
// conversion macros - for instance the above could
// be done as
// wxCommandEventHandler(wxMediaPlayerFrame::MyHandler)
// pretty simple, eh?
//
// The fourth is an optional userdata param -
// this is of historical relevance only and is
// there only for backwards compatibility.
//
// The fifth is the context in which to call the
// handler - by default (this param is optional)
// this. For example in your event handler
// if you were to call "this->MyFunc()"
// it would literally do this->MyFunc. However,
// if you were to pass myHandler as the fifth
// parameter, for instance, you would _really_
// be calling myHandler->MyFunc, even though
// the compiler doesn't really know it.
//
//
// Menu events
//
this->Connect(wxID_EXIT, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnQuit));
this->Connect(wxID_ABOUT, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnAbout));
this->Connect(wxID_LOOP, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnLoop));
this->Connect(wxID_SHOWINTERFACE, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnShowInterface));
this->Connect(wxID_OPENFILENEWPAGE, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnOpenFileNewPage));
this->Connect(wxID_OPENFILESAMEPAGE, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnOpenFileSamePage));
this->Connect(wxID_OPENURLNEWPAGE, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnOpenURLNewPage));
this->Connect(wxID_OPENURLSAMEPAGE, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnOpenURLSamePage));
this->Connect(wxID_CLOSECURRENTPAGE, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnCloseCurrentPage));
this->Connect(wxID_PLAY, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnPlay));
this->Connect(wxID_STOP, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnStop));
this->Connect(wxID_NEXT, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnNext));
this->Connect(wxID_PREV, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnPrev));
this->Connect(wxID_SELECTBACKEND, wxEVT_MENU,
wxCommandEventHandler(wxMediaPlayerFrame::OnSelectBackend));
//
// Key events
//
wxTheApp->Connect(wxID_ANY, wxEVT_KEY_DOWN,
wxKeyEventHandler(wxMediaPlayerFrame::OnKeyDown),
(wxObject*)0, this);
//
// Close events
//
this->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW,
wxCloseEventHandler(wxMediaPlayerFrame::OnClose));
//
// End of Events
//
//
// Create an initial notebook page so the user has something
// to work with without having to go file->open every time :).
//
wxMediaPlayerNotebookPage* page =
new wxMediaPlayerNotebookPage(this, m_notebook);
m_notebook->AddPage(page,
wxT(""),
true);
// Don't load previous files if we have some specified on the command line,
// we wouldn't play them otherwise (they'd have to be inserted into the
// play list at the beginning instead of being appended but we don't
// support this).
#if wxUSE_CMDLINE_PARSER
if ( wxGetApp().m_params.empty() )
#endif // wxUSE_CMDLINE_PARSER
{
//
// Here we load the our configuration -
// in our case we load all the files that were left in
// the playlist the last time the user closed our application
//
// As an exercise to the reader try modifying it so that
// it properly loads the playlist for each page without
// conflicting (loading the same data) with the other ones.
//
wxConfig conf;
wxString key, outstring;
for(int i = 0; ; ++i)
{
key.clear();
key << i;
if(!conf.Read(key, &outstring))
break;
page->m_playlist->AddToPlayList(outstring);
}
}
//
// Create a timer to update our status bar
//
m_timer = new wxMediaPlayerTimer(this);
m_timer->Start(500);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame Destructor
//
// 1) Deletes child objects implicitly
// 2) Delete our timer explicitly
// ----------------------------------------------------------------------------
wxMediaPlayerFrame::~wxMediaPlayerFrame()
{
// Shut down our timer
delete m_timer;
//
// Here we save our info to the registry or whatever
// mechanism the OS uses.
//
// This makes it so that when mediaplayer loads up again
// it restores the same files that were in the playlist
// this time, rather than the user manually re-adding them.
//
// We need to do conf->DeleteAll() here because by default
// the config still contains the same files as last time
// so we need to clear it before writing our new ones.
//
// TODO: Maybe you could add a menu option to the
// options menu to delete the configuration on exit -
// all you'd need to do is just remove everything after
// conf->DeleteAll() here
//
// As an exercise to the reader, try modifying this so
// that it saves the data for each notebook page
//
wxMediaPlayerListCtrl* playlist =
((wxMediaPlayerNotebookPage*)m_notebook->GetPage(0))->m_playlist;
wxConfig conf;
conf.DeleteAll();
for(int i = 0; i < playlist->GetItemCount(); ++i)
{
wxString* pData = (wxString*) playlist->GetItemData(i);
wxString s;
s << i;
conf.Write(s, *(pData));
delete pData;
}
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnClose
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnClose(wxCloseEvent& event)
{
event.Skip(); // really close the frame
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::AddToPlayList
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::AddToPlayList(const wxString& szString)
{
wxMediaPlayerNotebookPage* currentpage =
((wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage());
currentpage->m_playlist->AddToPlayList(szString);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnQuit
//
// Called from file->quit.
// Closes this application.
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
// true is to force the frame to close
Close(true);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnAbout
//
// Called from help->about.
// Gets some info about this application.
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxString msg;
msg.Printf( wxT("This is a test of wxMediaCtrl.\n\n")
wxT("Instructions:\n")
wxT("The top slider shows the current the current position, ")
wxT("which you can change by dragging and releasing it.\n")
wxT("The gauge (progress bar) shows the progress in ")
wxT("downloading data of the current file - it may always be ")
wxT("empty due to lack of support from the current backend.\n")
wxT("The lower-left slider controls the volume and the lower-")
wxT("right slider controls the playback rate/speed of the ")
wxT("media\n\n")
wxT("Currently using: %s"), wxVERSION_STRING);
wxMessageBox(msg, wxT("About wxMediaCtrl test"),
wxOK | wxICON_INFORMATION, this);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnLoop
//
// Called from file->loop.
// Changes the state of whether we want to loop or not.
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnLoop(wxCommandEvent& WXUNUSED(event))
{
wxMediaPlayerNotebookPage* currentpage =
((wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage());
currentpage->m_bLoop = !currentpage->m_bLoop;
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnLoop
//
// Called from file->loop.
// Changes the state of whether we want to loop or not.
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnShowInterface(wxCommandEvent& event)
{
wxMediaPlayerNotebookPage* currentpage =
((wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage());
if( !currentpage->m_mediactrl->ShowPlayerControls(event.IsChecked() ?
wxMEDIACTRLPLAYERCONTROLS_DEFAULT :
wxMEDIACTRLPLAYERCONTROLS_NONE) )
{
// error - uncheck and warn user
wxMenuItem* pSIItem = GetMenuBar()->FindItem(wxID_SHOWINTERFACE);
wxASSERT(pSIItem);
pSIItem->Check(!event.IsChecked());
if(event.IsChecked())
wxMessageBox(wxT("Could not show player controls"));
else
wxMessageBox(wxT("Could not hide player controls"));
}
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnOpenFileSamePage
//
// Called from file->openfile.
// Opens and plays a media file in the current notebook page
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnOpenFileSamePage(wxCommandEvent& WXUNUSED(event))
{
OpenFile(false);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnOpenFileNewPage
//
// Called from file->openfileinnewpage.
// Opens and plays a media file in a new notebook page
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnOpenFileNewPage(wxCommandEvent& WXUNUSED(event))
{
OpenFile(true);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OpenFile
//
// Opens a file dialog asking the user for a filename, then
// calls DoOpenFile which will add the file to the playlist and play it
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OpenFile(bool bNewPage)
{
wxFileDialog fd(this);
if(fd.ShowModal() == wxID_OK)
{
DoOpenFile(fd.GetPath(), bNewPage);
}
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::DoOpenFile
//
// Adds the file to our playlist, selects it in the playlist,
// and then calls DoPlayFile to play it
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::DoOpenFile(const wxString& path, bool bNewPage)
{
if(bNewPage)
{
m_notebook->AddPage(
new wxMediaPlayerNotebookPage(this, m_notebook),
path,
true);
}
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if(currentpage->m_nLastFileId != -1)
currentpage->m_playlist->SetItemState(currentpage->m_nLastFileId,
0, wxLIST_STATE_SELECTED);
wxListItem newlistitem;
newlistitem.SetAlign(wxLIST_FORMAT_LEFT);
int nID;
newlistitem.SetId(nID = currentpage->m_playlist->GetItemCount());
newlistitem.SetMask(wxLIST_MASK_DATA | wxLIST_MASK_STATE);
newlistitem.SetState(wxLIST_STATE_SELECTED);
newlistitem.SetData(new wxString(path));
currentpage->m_playlist->InsertItem(newlistitem);
currentpage->m_playlist->SetItem(nID, 0, wxT("*"));
currentpage->m_playlist->SetItem(nID, 1, wxFileName(path).GetName());
if (nID % 2)
{
newlistitem.SetBackgroundColour(wxColour(192,192,192));
currentpage->m_playlist->SetItem(newlistitem);
}
DoPlayFile(path);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::DoPlayFile
//
// Pauses the file if its the currently playing file,
// otherwise it plays the file
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::DoPlayFile(const wxString& path)
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
wxListItem listitem;
currentpage->m_playlist->GetSelectedItem(listitem);
if( ( listitem.GetData() &&
currentpage->m_nLastFileId == listitem.GetId() &&
currentpage->m_szFile.compare(path) == 0 ) ||
( !listitem.GetData() &&
currentpage->m_nLastFileId != -1 &&
currentpage->m_szFile.compare(path) == 0)
)
{
if(currentpage->m_mediactrl->GetState() == wxMEDIASTATE_PLAYING)
{
if( !currentpage->m_mediactrl->Pause() )
wxMessageBox(wxT("Couldn't pause movie!"));
}
else
{
if( !currentpage->m_mediactrl->Play() )
wxMessageBox(wxT("Couldn't play movie!"));
}
}
else
{
int nNewId = listitem.GetData() ? listitem.GetId() :
currentpage->m_playlist->GetItemCount()-1;
m_notebook->SetPageText(m_notebook->GetSelection(),
wxFileName(path).GetName());
if(currentpage->m_nLastFileId != -1)
currentpage->m_playlist->SetItem(
currentpage->m_nLastFileId, 0, wxT("*"));
wxURI uripath(path);
if( uripath.IsReference() )
{
if( !currentpage->m_mediactrl->Load(path) )
{
wxMessageBox(wxT("Couldn't load file!"));
currentpage->m_playlist->SetItem(nNewId, 0, wxT("E"));
}
else
{
currentpage->m_playlist->SetItem(nNewId, 0, wxT("O"));
}
}
else
{
if( !currentpage->m_mediactrl->Load(uripath) )
{
wxMessageBox(wxT("Couldn't load URL!"));
currentpage->m_playlist->SetItem(nNewId, 0, wxT("E"));
}
else
{
currentpage->m_playlist->SetItem(nNewId, 0, wxT("O"));
}
}
currentpage->m_nLastFileId = nNewId;
currentpage->m_szFile = path;
currentpage->m_playlist->SetItem(currentpage->m_nLastFileId,
1, wxFileName(path).GetName());
currentpage->m_playlist->SetItem(currentpage->m_nLastFileId,
2, wxT(""));
}
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnMediaLoaded
//
// Called when the media is ready to be played - and does
// so, also gets the length of media and shows that in the list control
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnMediaLoaded(wxMediaEvent& WXUNUSED(evt))
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if( !currentpage->m_mediactrl->Play() )
{
wxMessageBox(wxT("Couldn't play movie!"));
currentpage->m_playlist->SetItem(currentpage->m_nLastFileId, 0, wxT("E"));
}
else
{
currentpage->m_playlist->SetItem(currentpage->m_nLastFileId, 0, wxT(">"));
}
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnSelectBackend
//
// Little debugging routine - enter the class name of a backend and it
// will use that instead of letting wxMediaCtrl search the wxMediaBackend
// RTTI class list.
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnSelectBackend(wxCommandEvent& WXUNUSED(evt))
{
wxString sBackend = wxGetTextFromUser(wxT("Enter backend to use"));
if(sBackend.empty() == false) // could have been cancelled by the user
{
int sel = m_notebook->GetSelection();
if (sel != wxNOT_FOUND)
{
m_notebook->DeletePage(sel);
}
m_notebook->AddPage(new wxMediaPlayerNotebookPage(this, m_notebook,
sBackend
), wxT(""), true);
DoOpenFile(
((wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage())->m_szFile,
false);
}
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnOpenURLSamePage
//
// Called from file->openurl.
// Opens and plays a media file from a URL in the current notebook page
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnOpenURLSamePage(wxCommandEvent& WXUNUSED(event))
{
OpenURL(false);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnOpenURLNewPage
//
// Called from file->openurlinnewpage.
// Opens and plays a media file from a URL in a new notebook page
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnOpenURLNewPage(wxCommandEvent& WXUNUSED(event))
{
OpenURL(true);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OpenURL
//
// Just calls DoOpenFile with the url path - which calls DoPlayFile
// which handles the real dirty work
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OpenURL(bool bNewPage)
{
wxString sUrl = wxGetTextFromUser(
wxT("Enter the URL that has the movie to play")
);
if(sUrl.empty() == false) // could have been cancelled by user
{
DoOpenFile(sUrl, bNewPage);
}
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnCloseCurrentPage
//
// Called when the user wants to close the current notebook page
//
// 1) Get the current page number (wxControl::GetSelection)
// 2) If there is no current page, break out
// 3) Delete the current page
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnCloseCurrentPage(wxCommandEvent& WXUNUSED(event))
{
if( m_notebook->GetPageCount() > 1 )
{
int sel = m_notebook->GetSelection();
if (sel != wxNOT_FOUND)
{
m_notebook->DeletePage(sel);
}
}
else
{
wxMessageBox(wxT("Cannot close main page"));
}
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnPlay
//
// Called from file->play.
// Resumes the media if it is paused or stopped.
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
wxListItem listitem;
currentpage->m_playlist->GetSelectedItem(listitem);
if ( !listitem.GetData() )
{
int nLast = -1;
if ((nLast = currentpage->m_playlist->GetNextItem(nLast,
wxLIST_NEXT_ALL,
wxLIST_STATE_DONTCARE)) == -1)
{
// no items in list
wxMessageBox(wxT("No items in playlist!"));
}
else
{
listitem.SetId(nLast);
currentpage->m_playlist->GetItem(listitem);
listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
currentpage->m_playlist->SetItem(listitem);
wxASSERT(listitem.GetData());
DoPlayFile((*((wxString*) listitem.GetData())));
}
}
else
{
wxASSERT(listitem.GetData());
DoPlayFile((*((wxString*) listitem.GetData())));
}
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnKeyDown
//
// Deletes all selected files from the playlist if the backspace key is pressed
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnKeyDown(wxKeyEvent& event)
{
if(event.GetKeyCode() == WXK_BACK/*DELETE*/)
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
// delete all selected items
while(true)
{
wxInt32 nSelectedItem = currentpage->m_playlist->GetNextItem(
-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (nSelectedItem == -1)
break;
wxListItem listitem;
listitem.SetId(nSelectedItem);
currentpage->m_playlist->GetItem(listitem);
delete (wxString*) listitem.GetData();
currentpage->m_playlist->DeleteItem(nSelectedItem);
}
}
// Could be wxGetTextFromUser or something else important
if(event.GetEventObject() != this)
event.Skip();
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnStop
//
// Called from file->stop.
// Where it stops depends on whether you can seek in the
// media control or not - if you can it stops and seeks to the beginning,
// otherwise it will appear to be at the end - but it will start over again
// when Play() is called
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnStop(wxCommandEvent& WXUNUSED(evt))
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if( !currentpage->m_mediactrl->Stop() )
wxMessageBox(wxT("Couldn't stop movie!"));
else
currentpage->m_playlist->SetItem(
currentpage->m_nLastFileId, 0, wxT("[]"));
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnChangeSong
//
// Routine that plays the currently selected file in the playlist.
// Called when the user actives the song from the playlist,
// and from other various places in the sample
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnChangeSong(wxListEvent& WXUNUSED(evt))
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
wxListItem listitem;
currentpage->m_playlist->GetSelectedItem(listitem);
if(listitem.GetData())
DoPlayFile((*((wxString*) listitem.GetData())));
else
wxMessageBox(wxT("No selected item!"));
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnPrev
//
// Tedious wxListCtrl stuff. Goes to prevous song in list, or if at the
// beginning goes to the last in the list.
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnPrev(wxCommandEvent& WXUNUSED(event))
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if (currentpage->m_playlist->GetItemCount() == 0)
return;
wxInt32 nLastSelectedItem = -1;
while(true)
{
wxInt32 nSelectedItem = currentpage->m_playlist->GetNextItem(nLastSelectedItem,
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (nSelectedItem == -1)
break;
nLastSelectedItem = nSelectedItem;
currentpage->m_playlist->SetItemState(nSelectedItem, 0, wxLIST_STATE_SELECTED);
}
if (nLastSelectedItem == -1)
{
// nothing selected, default to the file before the currently playing one
if(currentpage->m_nLastFileId == 0)
nLastSelectedItem = currentpage->m_playlist->GetItemCount() - 1;
else
nLastSelectedItem = currentpage->m_nLastFileId - 1;
}
else if (nLastSelectedItem == 0)
nLastSelectedItem = currentpage->m_playlist->GetItemCount() - 1;
else
nLastSelectedItem -= 1;
if(nLastSelectedItem == currentpage->m_nLastFileId)
return; // already playing... nothing to do
wxListItem listitem;
listitem.SetId(nLastSelectedItem);
listitem.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_DATA);
currentpage->m_playlist->GetItem(listitem);
listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
currentpage->m_playlist->SetItem(listitem);
wxASSERT(listitem.GetData());
DoPlayFile((*((wxString*) listitem.GetData())));
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnNext
//
// Tedious wxListCtrl stuff. Goes to next song in list, or if at the
// end goes to the first in the list.
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnNext(wxCommandEvent& WXUNUSED(event))
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
if (currentpage->m_playlist->GetItemCount() == 0)
return;
wxInt32 nLastSelectedItem = -1;
while(true)
{
wxInt32 nSelectedItem = currentpage->m_playlist->GetNextItem(nLastSelectedItem,
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (nSelectedItem == -1)
break;
nLastSelectedItem = nSelectedItem;
currentpage->m_playlist->SetItemState(nSelectedItem, 0, wxLIST_STATE_SELECTED);
}
if (nLastSelectedItem == -1)
{
if(currentpage->m_nLastFileId == currentpage->m_playlist->GetItemCount() - 1)
nLastSelectedItem = 0;
else
nLastSelectedItem = currentpage->m_nLastFileId + 1;
}
else if (nLastSelectedItem == currentpage->m_playlist->GetItemCount() - 1)
nLastSelectedItem = 0;
else
nLastSelectedItem += 1;
if(nLastSelectedItem == currentpage->m_nLastFileId)
return; // already playing... nothing to do
wxListItem listitem;
listitem.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_DATA);
listitem.SetId(nLastSelectedItem);
currentpage->m_playlist->GetItem(listitem);
listitem.SetMask(listitem.GetMask() | wxLIST_MASK_STATE);
listitem.SetState(listitem.GetState() | wxLIST_STATE_SELECTED);
currentpage->m_playlist->SetItem(listitem);
wxASSERT(listitem.GetData());
DoPlayFile((*((wxString*) listitem.GetData())));
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnVolumeDown
//
// Lowers the volume of the media control by 5%
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnVolumeDown(wxCommandEvent& WXUNUSED(event))
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
double dVolume = currentpage->m_mediactrl->GetVolume();
currentpage->m_mediactrl->SetVolume(dVolume < 0.05 ? 0.0 : dVolume - .05);
}
// ----------------------------------------------------------------------------
// wxMediaPlayerFrame::OnVolumeUp
//
// Increases the volume of the media control by 5%
// ----------------------------------------------------------------------------
void wxMediaPlayerFrame::OnVolumeUp(wxCommandEvent& WXUNUSED(event))
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_notebook->GetCurrentPage();
double dVolume = currentpage->m_mediactrl->GetVolume();
currentpage->m_mediactrl->SetVolume(dVolume > 0.95 ? 1.0 : dVolume + .05);
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// wxMediaPlayerTimer
//
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ----------------------------------------------------------------------------
// wxMediaPlayerTimer::Notify
//
// 1) Updates media information on the status bar
// 2) Sets the max/min length of the slider and guage
//
// Note that the reason we continually do this and don't cache it is because
// some backends such as GStreamer are dynamic change values all the time
// and often don't have things like duration or video size available
// until the media is actually being played
// ----------------------------------------------------------------------------
void wxMediaPlayerTimer::Notify()
{
wxMediaPlayerNotebookPage* currentpage =
(wxMediaPlayerNotebookPage*) m_frame->m_notebook->GetCurrentPage();
wxMediaCtrl* currentMediaCtrl = currentpage->m_mediactrl;
// Number of minutes/seconds total
wxLongLong llLength = currentpage->m_mediactrl->Length();
int nMinutes = (int) (llLength / 60000).GetValue();
int nSeconds = (int) ((llLength % 60000)/1000).GetValue();
// Duration string (i.e. MM:SS)
wxString sDuration;
sDuration.Printf(wxT("%2i:%02i"), nMinutes, nSeconds);
// Number of minutes/seconds total
wxLongLong llTell = currentpage->m_mediactrl->Tell();
nMinutes = (int) (llTell / 60000).GetValue();
nSeconds = (int) ((llTell % 60000)/1000).GetValue();
// Position string (i.e. MM:SS)
wxString sPosition;
sPosition.Printf(wxT("%2i:%02i"), nMinutes, nSeconds);
// Set the third item in the listctrl entry to the duration string
if(currentpage->m_nLastFileId >= 0)
currentpage->m_playlist->SetItem(
currentpage->m_nLastFileId, 2, sDuration);
// Setup the slider and gauge min/max values
currentpage->m_slider->SetRange(0, (int)(llLength / 1000).GetValue());
currentpage->m_gauge->SetRange(100);
// if the slider is not being dragged then update it with the song position
if(currentpage->IsBeingDragged() == false)
currentpage->m_slider->SetValue((long)(llTell / 1000).GetValue());
// Update the gauge with the download progress
wxLongLong llDownloadProgress =
currentpage->m_mediactrl->GetDownloadProgress();
wxLongLong llDownloadTotal =
currentpage->m_mediactrl->GetDownloadTotal();
if(llDownloadTotal.GetValue() != 0)
{
currentpage->m_gauge->SetValue(
(int) ((llDownloadProgress * 100) / llDownloadTotal).GetValue()
);
}
// GetBestSize holds the original video size
wxSize videoSize = currentMediaCtrl->GetBestSize();
// Now the big part - set the status bar text to
// hold various metadata about the media
#if wxUSE_STATUSBAR
m_frame->SetStatusText(wxString::Format(
wxT("Size(x,y):%i,%i ")
wxT("Position:%s/%s Speed:%1.1fx ")
wxT("State:%s Loops:%i D/T:[%i]/[%i] V:%i%%"),
videoSize.x,
videoSize.y,
sPosition.c_str(),
sDuration.c_str(),
currentMediaCtrl->GetPlaybackRate(),
wxGetMediaStateText(currentpage->m_mediactrl->GetState()),
currentpage->m_nLoops,
(int)llDownloadProgress.GetValue(),
(int)llDownloadTotal.GetValue(),
(int)(currentpage->m_mediactrl->GetVolume() * 100)));
#endif // wxUSE_STATUSBAR
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// wxMediaPlayerNotebookPage
//
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ----------------------------------------------------------------------------
// wxMediaPlayerNotebookPage Constructor
//
// Creates a media control and slider and adds it to this panel,
// along with some sizers for positioning
// ----------------------------------------------------------------------------
wxMediaPlayerNotebookPage::wxMediaPlayerNotebookPage(wxMediaPlayerFrame* parentFrame,
wxNotebook* theBook,
const wxString& szBackend)
: wxPanel(theBook, wxID_ANY),
m_nLastFileId(-1),
m_nLoops(0),
m_bLoop(false),
m_bIsBeingDragged(false),
m_parentFrame(parentFrame)
{
//
// Layout
//
// [wxMediaCtrl]
// [playlist]
// [5 control buttons]
// [slider]
// [gauge]
//
//
// Create and attach a 2-column grid sizer
//
wxFlexGridSizer* sizer = new wxFlexGridSizer(2);
sizer->AddGrowableCol(0);
this->SetSizer(sizer);
//
// Create our media control
//
m_mediactrl = new wxMediaCtrl();
// Make sure creation was successful
bool bOK = m_mediactrl->Create(this, wxID_MEDIACTRL, wxEmptyString,
wxDefaultPosition, wxDefaultSize, 0,
// you could specify a macro backend here like
// wxMEDIABACKEND_WMP10);
// wxT("wxPDFMediaBackend"));
szBackend);
// you could change the cursor here like
// m_mediactrl->SetCursor(wxCURSOR_BLANK);
// note that this may not effect it if SetPlayerControls
// is set to something else than wxMEDIACTRLPLAYERCONTROLS_NONE
wxASSERT_MSG(bOK, wxT("Could not create media control!"));
wxUnusedVar(bOK);
sizer->Add(m_mediactrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5);
//
// Create the playlist/listctrl
//
m_playlist = new wxMediaPlayerListCtrl();
m_playlist->Create(this, wxID_LISTCTRL, wxDefaultPosition,
wxDefaultSize,
wxLC_REPORT // wxLC_LIST
| wxSUNKEN_BORDER);
// Set the background of our listctrl to white
m_playlist->SetBackgroundColour(*wxWHITE);
// The layout of the headers of the listctrl are like
// | | File | Length
//
// Where Column one is a character representing the state the file is in:
// * - not the current file
// E - Error has occured
// > - Currently Playing
// [] - Stopped
// || - Paused
// (( - Volume Down 5%
// )) - Volume Up 5%
//
// Column two is the name of the file
//
// Column three is the length in seconds of the file
m_playlist->AppendColumn(_(""), wxLIST_FORMAT_CENTER, 20);
m_playlist->AppendColumn(_("File"), wxLIST_FORMAT_LEFT, /*wxLIST_AUTOSIZE_USEHEADER*/305);
m_playlist->AppendColumn(_("Length"), wxLIST_FORMAT_CENTER, 75);
#if wxUSE_DRAG_AND_DROP
m_playlist->SetDropTarget(new wxPlayListDropTarget(*m_playlist));
#endif
sizer->Add(m_playlist, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5);
//
// Create the control buttons
// TODO/FIXME/HACK: This part about sizers is really a nice hack
// and probably isn't proper
//
wxBoxSizer* horsizer1 = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* vertsizer = new wxBoxSizer(wxHORIZONTAL);
m_prevButton = new wxButton();
m_playButton = new wxButton();
m_stopButton = new wxButton();
m_nextButton = new wxButton();
m_vdButton = new wxButton();
m_vuButton = new wxButton();
m_prevButton->Create(this, wxID_BUTTONPREV, wxT("|<"));
m_prevButton->SetToolTip("Previous");
m_playButton->Create(this, wxID_BUTTONPLAY, wxT(">"));
m_playButton->SetToolTip("Play");
m_stopButton->Create(this, wxID_BUTTONSTOP, wxT("[]"));
m_stopButton->SetToolTip("Stop");
m_nextButton->Create(this, wxID_BUTTONNEXT, wxT(">|"));
m_nextButton->SetToolTip("Next");
m_vdButton->Create(this, wxID_BUTTONVD, wxT("(("));
m_vdButton->SetToolTip("Volume down");
m_vuButton->Create(this, wxID_BUTTONVU, wxT("))"));
m_vuButton->SetToolTip("Volume up");
vertsizer->Add(m_prevButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
vertsizer->Add(m_playButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
vertsizer->Add(m_stopButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
vertsizer->Add(m_nextButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
vertsizer->Add(m_vdButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
vertsizer->Add(m_vuButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
horsizer1->Add(vertsizer, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
sizer->Add(horsizer1, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
//
// Create our slider
//
m_slider = new wxSlider(this, wxID_SLIDER, 0, // init
0, // start
1, // end, dummy but must be greater than start
wxDefaultPosition, wxDefaultSize,
wxSL_HORIZONTAL );
sizer->Add(m_slider, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND , 5);
//
// Create the gauge
//
m_gauge = new wxGauge();
m_gauge->Create(this, wxID_GAUGE, 0, wxDefaultPosition, wxDefaultSize,
wxGA_HORIZONTAL | wxGA_SMOOTH);
sizer->Add(m_gauge, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND , 5);
//
// Create the speed/volume sliders
//
wxBoxSizer* horsizer3 = new wxBoxSizer(wxHORIZONTAL);
m_volSlider = new wxSlider(this, wxID_VOLSLIDER, 100, // init
0, // start
100, // end
wxDefaultPosition, wxSize(250,20),
wxSL_HORIZONTAL );
horsizer3->Add(m_volSlider, 1, wxALL, 5);
m_pbSlider = new wxSlider(this, wxID_PBSLIDER, 4, // init
1, // start
16, // end
wxDefaultPosition, wxSize(250,20),
wxSL_HORIZONTAL );
horsizer3->Add(m_pbSlider, 1, wxALL, 5);
sizer->Add(horsizer3, 1, wxCENTRE | wxALL, 5);
// Now that we have all our rows make some of them growable
sizer->AddGrowableRow(0);
//
// ListCtrl events
//
this->Connect( wxID_LISTCTRL, wxEVT_LIST_ITEM_ACTIVATED,
wxListEventHandler(wxMediaPlayerFrame::OnChangeSong),
(wxObject*)0, parentFrame);
//
// Slider events
//
this->Connect(wxID_SLIDER, wxEVT_SCROLL_THUMBTRACK,
wxScrollEventHandler(wxMediaPlayerNotebookPage::OnBeginSeek));
this->Connect(wxID_SLIDER, wxEVT_SCROLL_THUMBRELEASE,
wxScrollEventHandler(wxMediaPlayerNotebookPage::OnEndSeek));
this->Connect(wxID_PBSLIDER, wxEVT_SCROLL_THUMBRELEASE,
wxScrollEventHandler(wxMediaPlayerNotebookPage::OnPBChange));
this->Connect(wxID_VOLSLIDER, wxEVT_SCROLL_THUMBRELEASE,
wxScrollEventHandler(wxMediaPlayerNotebookPage::OnVolChange));
//
// Media Control events
//
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_PLAY,
wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaPlay));
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_PAUSE,
wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaPause));
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_STOP,
wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaStop));
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_FINISHED,
wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaFinished));
this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_LOADED,
wxMediaEventHandler(wxMediaPlayerFrame::OnMediaLoaded),
(wxObject*)0, parentFrame);
//
// Button events
//
this->Connect( wxID_BUTTONPREV, wxEVT_BUTTON,
wxCommandEventHandler(wxMediaPlayerFrame::OnPrev),
(wxObject*)0, parentFrame);
this->Connect( wxID_BUTTONPLAY, wxEVT_BUTTON,
wxCommandEventHandler(wxMediaPlayerFrame::OnPlay),
(wxObject*)0, parentFrame);
this->Connect( wxID_BUTTONSTOP, wxEVT_BUTTON,
wxCommandEventHandler(wxMediaPlayerFrame::OnStop),
(wxObject*)0, parentFrame);
this->Connect( wxID_BUTTONNEXT, wxEVT_BUTTON,
wxCommandEventHandler(wxMediaPlayerFrame::OnNext),
(wxObject*)0, parentFrame);
this->Connect( wxID_BUTTONVD, wxEVT_BUTTON,
wxCommandEventHandler(wxMediaPlayerFrame::OnVolumeDown),
(wxObject*)0, parentFrame);
this->Connect( wxID_BUTTONVU, wxEVT_BUTTON,
wxCommandEventHandler(wxMediaPlayerFrame::OnVolumeUp),
(wxObject*)0, parentFrame);
}
// ----------------------------------------------------------------------------
// MyNotebook::OnBeginSeek
//
// Sets m_bIsBeingDragged to true to stop the timer from changing the position
// of our slider
// ----------------------------------------------------------------------------
void wxMediaPlayerNotebookPage::OnBeginSeek(wxScrollEvent& WXUNUSED(event))
{
m_bIsBeingDragged = true;
}
// ----------------------------------------------------------------------------
// MyNotebook::OnEndSeek
//
// Called from file->seek.
// Called when the user moves the slider -
// seeks to a position within the media
// then sets m_bIsBeingDragged to false to ok the timer to change the position
// ----------------------------------------------------------------------------
void wxMediaPlayerNotebookPage::OnEndSeek(wxScrollEvent& WXUNUSED(event))
{
if( m_mediactrl->Seek(
m_slider->GetValue() * 1000
) == wxInvalidOffset )
wxMessageBox(wxT("Couldn't seek in movie!"));
m_bIsBeingDragged = false;
}
// ----------------------------------------------------------------------------
// wxMediaPlayerNotebookPage::IsBeingDragged
//
// Returns true if the user is dragging the slider
// ----------------------------------------------------------------------------
bool wxMediaPlayerNotebookPage::IsBeingDragged()
{
return m_bIsBeingDragged;
}
// ----------------------------------------------------------------------------
// wxMediaPlayerNotebookPage::OnVolChange
//
// Called when the user is done dragging the volume-changing slider
// ----------------------------------------------------------------------------
void wxMediaPlayerNotebookPage::OnVolChange(wxScrollEvent& WXUNUSED(event))
{
if( m_mediactrl->SetVolume(
m_volSlider->GetValue() / 100.0
) == false )
wxMessageBox(wxT("Couldn't set volume!"));
}
// ----------------------------------------------------------------------------
// wxMediaPlayerNotebookPage::OnPBChange
//
// Called when the user is done dragging the speed-changing slider
// ----------------------------------------------------------------------------
void wxMediaPlayerNotebookPage::OnPBChange(wxScrollEvent& WXUNUSED(event))
{
if( m_mediactrl->SetPlaybackRate(
m_pbSlider->GetValue() * .25
) == false )
wxMessageBox(wxT("Couldn't set playbackrate!"));
}
// ----------------------------------------------------------------------------
// wxMediaPlayerNotebookPage::OnMediaPlay
//
// Called when the media plays.
// ----------------------------------------------------------------------------
void wxMediaPlayerNotebookPage::OnMediaPlay(wxMediaEvent& WXUNUSED(event))
{
m_playlist->SetItem(m_nLastFileId, 0, wxT(">"));
}
// ----------------------------------------------------------------------------
// wxMediaPlayerNotebookPage::OnMediaPause
//
// Called when the media is paused.
// ----------------------------------------------------------------------------
void wxMediaPlayerNotebookPage::OnMediaPause(wxMediaEvent& WXUNUSED(event))
{
m_playlist->SetItem(m_nLastFileId, 0, wxT("||"));
}
// ----------------------------------------------------------------------------
// wxMediaPlayerNotebookPage::OnMediaStop
//
// Called when the media stops.
// ----------------------------------------------------------------------------
void wxMediaPlayerNotebookPage::OnMediaStop(wxMediaEvent& WXUNUSED(event))
{
m_playlist->SetItem(m_nLastFileId, 0, wxT("[]"));
}
// ----------------------------------------------------------------------------
// wxMediaPlayerNotebookPage::OnMediaFinished
//
// Called when the media finishes playing.
// Here we loop it if the user wants to (has been selected from file menu)
// ----------------------------------------------------------------------------
void wxMediaPlayerNotebookPage::OnMediaFinished(wxMediaEvent& WXUNUSED(event))
{
if(m_bLoop)
{
if ( !m_mediactrl->Play() )
{
wxMessageBox(wxT("Couldn't loop movie!"));
m_playlist->SetItem(m_nLastFileId, 0, wxT("E"));
}
else
++m_nLoops;
}
else
{
m_playlist->SetItem(m_nLastFileId, 0, wxT("[]"));
}
}
//
// End of MediaPlayer sample
//
|