Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 | 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 117x 117x 111x 117x 117x 111x 117x 117x 117x 109x 117x 111x 117x 117x 117x 117x 117x 111x 117x 111x 117x 111x 117x 117x 111x 117x 111x 117x 6x 47x 47x 47x 47x 2x 2x 45x 45x 45x 45x 2x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 44x 45x 142x 1x 1x 45x 111x 4x 1x 3x 3x 3x 1x 2x 4x 1x 3x 3x 1x 2x 1x 1x 1x 1x 3x 1x 2x 2x 2x 6x 5x 6x 6x 1x 5x 4x 3x 3x 1x 3x 2x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 6x 1x 5x 5x 1x 5x 3x 3x 1x 2x 2x 2x 2x 2x 5x 1x 4x 4x 4x 1x 3x 3x 3x 2x 3x 5x 1x 4x 4x 1x 1x 1x 4x 2x 1x 1x 1x 48x 46x 2x 1x 1x 8x 2x 5x 2x 1x 1x 46x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 85x 8x 77x 49x 1x 48x 47x 46x 46x 46x 46x 46x 47x 2x 2x 47x 2x 1x 1x 3x 3x 1x 1x 5x 1x 4x 4x 4x 4x 2x 1x 1x 2x 1x 1x 1x 1x 5x 1x 4x 4x 6x 1x 5x 2x 1x 1x 1x 1x 45x 1x 44x 44x 44x 44x 44x 44x 44x 44x 44x 4x 1x 3x 1x 2x 2x 2x 2x 2x 1x 1x 1x 2x 2x 50x 25x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 46x 46x 46x 44x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 1x 45x 45x 45x 45x 46x 46x 46x 45x 45x 45x 45x 45x 45x 4x 4x 10x 10x 10x 10x 5x 5x 5x 5x 5x 10x 4x 4x 1x 4x 4x 2x 4x 2x 4x 3x 3x 4x 3x 4x 91x 91x 46x 46x 46x 46x 46x 91x 45x 45x 45x 111x 111x 111x 1x 1x 1x 1x 1x | /**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import AbrController from './controllers/AbrController.js';
import BASE64 from '../../externals/base64.js';
import BaseURLController from './controllers/BaseURLController.js';
import BoxParser from './utils/BoxParser.js';
import Capabilities from './utils/Capabilities.js';
import CapabilitiesFilter from './utils/CapabilitiesFilter.js';
import CatchupController from './controllers/CatchupController.js';
import ClientDataReportingController from './controllers/ClientDataReportingController.js';
import CmcdModel from './models/CmcdModel.js';
import CmsdModel from './models/CmsdModel.js';
import Constants from './constants/Constants.js';
import ContentSteeringController from '../dash/controllers/ContentSteeringController.js';
import CustomParametersModel from './models/CustomParametersModel.js';
import DOMStorage from './utils/DOMStorage.js';
import DashAdapter from '../dash/DashAdapter.js';
import DashConstants from '../dash/constants/DashConstants.js';
import DashJSError from './vo/DashJSError.js';
import DashMetrics from '../dash/DashMetrics.js';
import Debug from './../core/Debug.js';
import ErrorHandler from './utils/ErrorHandler.js';
import Errors from './../core/errors/Errors.js';
import EventBus from './../core/EventBus.js';
import Events from './../core/events/Events.js';
import ExternalSubtitle from './vo/ExternalSubtitle.js';
import FactoryMaker from '../core/FactoryMaker.js';
import GapController from './controllers/GapController.js';
import ISOBoxer from 'codem-isoboxer';
import ManifestLoader from './ManifestLoader.js';
import ManifestModel from './models/ManifestModel.js';
import ManifestUpdater from './ManifestUpdater.js';
import MediaController from './controllers/MediaController.js';
import MediaPlayerEvents from './MediaPlayerEvents.js';
import MediaPlayerModel from './models/MediaPlayerModel.js';
import MetricsConstants from './constants/MetricsConstants.js';
import PlaybackController from './controllers/PlaybackController.js';
import SchemeLoaderFactory from './net/SchemeLoaderFactory.js';
import SegmentBaseController from '../dash/controllers/SegmentBaseController.js';
import ServiceDescriptionController from '../dash/controllers/ServiceDescriptionController.js';
import Settings from '../core/Settings.js';
import StreamController from './controllers/StreamController.js';
import TextController from './text/TextController.js';
import ThroughputController from './controllers/ThroughputController.js';
import TimelineConverter from '../dash/utils/TimelineConverter.js';
import URIFragmentModel from './models/URIFragmentModel.js';
import URLUtils from '../streaming/utils/URLUtils.js';
import VideoModel from './models/VideoModel.js';
import {Cta608Parser} from '@svta/common-media-library/cta/608/Cta608Parser';
import {HTTPRequest} from './vo/metrics/HTTPRequest.js';
import {checkParameterType} from './utils/SupervisorTools.js';
import {getVersionString} from '../core/Version.js';
/**
* The media types
* @typedef {('video' | 'audio' | 'text' | 'image')} MediaType
*/
/**
* @module MediaPlayer
* @description The MediaPlayer is the primary dash.js Module and a Facade to build your player around.
* It will allow you access to all the important dash.js properties/methods via the public API and all the
* events to build a robust DASH media player.
*/
function MediaPlayer() {
/**
* @constant {string} STREAMING_NOT_INITIALIZED_ERROR error string thrown when a function is called before the dash.js has been fully initialized
* @inner
*/
const STREAMING_NOT_INITIALIZED_ERROR = 'You must first call initialize() and set a source before calling this method';
/**
* @constant {string} PLAYBACK_NOT_INITIALIZED_ERROR error string thrown when a function is called before the dash.js has been fully initialized
* @inner
*/
const PLAYBACK_NOT_INITIALIZED_ERROR = 'You must first call initialize() and set a valid source and view before calling this method';
/**
* @constant {string} ELEMENT_NOT_ATTACHED_ERROR error string thrown when a function is called before the dash.js has received a reference of an HTML5 video element
* @inner
*/
const ELEMENT_NOT_ATTACHED_ERROR = 'You must first call attachView() to set the video element before calling this method';
/**
* @constant {string} SOURCE_NOT_ATTACHED_ERROR error string thrown when a function is called before the dash.js has received a valid source stream.
* @inner
*/
const SOURCE_NOT_ATTACHED_ERROR = 'You must first call attachSource() with a valid source before calling this method';
/**
* @constant {string} MEDIA_PLAYER_NOT_INITIALIZED_ERROR error string thrown when a function is called before the dash.js has been fully initialized.
* @inner
*/
const MEDIA_PLAYER_NOT_INITIALIZED_ERROR = 'MediaPlayer not initialized!';
/**
* @constant {string} ARRAY_NOT_SUPPORTED_ERROR error string thrown when settings object was called using an array.
* @inner
*/
const ARRAY_NOT_SUPPORTED_ERROR = 'Array type not supported for settings!';
const context = this.context;
const eventBus = EventBus(context).getInstance();
let settings = Settings(context).getInstance();
const debug = Debug(context).getInstance({ settings: settings });
let instance,
logger,
source,
protectionData,
mediaPlayerInitialized,
streamingInitialized,
playbackInitialized,
autoPlay,
providedStartTime,
abrController,
throughputController,
schemeLoaderFactory,
timelineConverter,
mediaController,
protectionController,
metricsReportingController,
mssHandler,
offlineController,
adapter,
mediaPlayerModel,
customParametersModel,
errHandler,
baseURLController,
capabilities,
capabilitiesFilter,
streamController,
textController,
gapController,
playbackController,
serviceDescriptionController,
contentSteeringController,
catchupController,
dashMetrics,
manifestModel,
cmcdModel,
cmsdModel,
videoModel,
uriFragmentModel,
domStorage,
segmentBaseController,
clientDataReportingController;
/*
---------------------------------------------------------------------------
INIT FUNCTIONS
---------------------------------------------------------------------------
*/
function setup() {
logger = debug.getLogger(instance);
mediaPlayerInitialized = false;
playbackInitialized = false;
streamingInitialized = false;
autoPlay = true;
providedStartTime = NaN;
protectionController = null;
offlineController = null;
protectionData = null;
adapter = null;
segmentBaseController = null;
Events.extend(MediaPlayerEvents);
mediaPlayerModel = MediaPlayerModel(context).getInstance();
customParametersModel = CustomParametersModel(context).getInstance();
videoModel = VideoModel(context).getInstance();
uriFragmentModel = URIFragmentModel(context).getInstance();
}
/**
* Configure media player with customs controllers. Helpful for tests
*
* @param {object=} config controllers configuration
* @memberof module:MediaPlayer
* @instance
*/
function setConfig(config) {
Iif (!config) {
return;
}
if (config.capabilities) {
capabilities = config.capabilities;
}
Iif (config.capabilitiesFilter) {
capabilitiesFilter = config.capabilitiesFilter;
}
if (config.streamController) {
streamController = config.streamController;
}
Iif (config.textController) {
textController = config.textController;
}
Iif (config.gapController) {
gapController = config.gapController;
}
if (config.throughputController) {
throughputController = config.throughputController
}
if (config.playbackController) {
playbackController = config.playbackController;
}
Iif (config.serviceDescriptionController) {
serviceDescriptionController = config.serviceDescriptionController
}
Iif (config.contentSteeringController) {
contentSteeringController = config.contentSteeringController;
}
Iif (config.clientDataReportingController) {
clientDataReportingController = config.clientDataReportingController;
}
Iif (config.catchupController) {
catchupController = config.catchupController;
}
if (config.mediaPlayerModel) {
mediaPlayerModel = config.mediaPlayerModel;
}
if (config.customParametersModel) {
customParametersModel = config.customParametersModel;
}
if (config.abrController) {
abrController = config.abrController;
}
Iif (config.schemeLoaderFactory) {
schemeLoaderFactory = config.schemeLoaderFactory;
}
if (config.mediaController) {
mediaController = config.mediaController;
}
if (config.settings) {
settings = config.settings;
}
if (config.dashMetrics) {
dashMetrics = config.dashMetrics;
}
}
/**
* Upon creating the MediaPlayer you must call initialize before you call anything else.
* There is one exception to this rule. It is crucial to call {@link module:MediaPlayer#extend extend()}
* with all your extensions prior to calling initialize.
*
* ALL arguments are optional and there are individual methods to set each argument later on.
* The args in this method are just for convenience and should only be used for a simple player setup.
*
* @param {HTML5MediaElement=} view - Optional arg to set the video element. {@link module:MediaPlayer#attachView attachView()}
* @param {string=} source - Optional arg to set the media source. {@link module:MediaPlayer#attachSource attachSource()}
* @param {boolean=} autoPlay - Optional arg to set auto play. {@link module:MediaPlayer#setAutoPlay setAutoPlay()}
* @param {number|string} startTime - For VoD content the start time is relative to the start time of the first period.
* For live content
* If the parameter starts from prefix posix: it signifies the absolute time range defined in seconds of Coordinated Universal Time (ITU-R TF.460-6). This is the number of seconds since 01-01-1970 00:00:00 UTC. Fractions of seconds may be optionally specified down to the millisecond level.
* If no posix prefix is used the starttime is relative to MPD@availabilityStartTime
* @see {@link module:MediaPlayer#attachSource attachSource()}
* @see {@link module:MediaPlayer#setAutoPlay setAutoPlay()}
* @memberof module:MediaPlayer
* @instance
*/
function initialize(view, source, autoPlay, startTime = NaN) {
Iif (!capabilities) {
capabilities = Capabilities(context).getInstance();
capabilities.setConfig({
settings,
protectionController
})
}
if (!errHandler) {
errHandler = ErrorHandler(context).getInstance();
}
if (!capabilities.supportsMediaSource()) {
errHandler.error(new DashJSError(Errors.CAPABILITY_MEDIASOURCE_ERROR_CODE, Errors.CAPABILITY_MEDIASOURCE_ERROR_MESSAGE));
return;
}
if (!mediaPlayerInitialized) {
mediaPlayerInitialized = true;
// init some controllers and models
timelineConverter = TimelineConverter(context).getInstance();
if (!throughputController) {
throughputController = ThroughputController(context).getInstance();
}
Iif (!abrController) {
abrController = AbrController(context).getInstance();
}
if (!schemeLoaderFactory) {
schemeLoaderFactory = SchemeLoaderFactory(context).getInstance();
}
Iif (!playbackController) {
playbackController = PlaybackController(context).getInstance();
}
Iif (!mediaController) {
mediaController = MediaController(context).getInstance();
}
Iif (!streamController) {
streamController = StreamController(context).getInstance();
}
if (!gapController) {
gapController = GapController(context).getInstance();
}
if (!catchupController) {
catchupController = CatchupController(context).getInstance();
}
if (!serviceDescriptionController) {
serviceDescriptionController = ServiceDescriptionController(context).getInstance();
}
if (!contentSteeringController) {
contentSteeringController = ContentSteeringController(context).getInstance();
}
if (!capabilitiesFilter) {
capabilitiesFilter = CapabilitiesFilter(context).getInstance();
}
adapter = DashAdapter(context).getInstance();
manifestModel = ManifestModel(context).getInstance();
cmcdModel = CmcdModel(context).getInstance();
cmsdModel = CmsdModel(context).getInstance();
clientDataReportingController = ClientDataReportingController(context).getInstance();
dashMetrics = DashMetrics(context).getInstance({
settings: settings
});
domStorage = DOMStorage(context).getInstance({
settings: settings
});
adapter.setConfig({
constants: Constants,
cea608parser: new Cta608Parser(),
errHandler: errHandler,
BASE64: BASE64
});
if (!baseURLController) {
baseURLController = BaseURLController(context).create();
}
baseURLController.setConfig({
adapter,
contentSteeringController
});
serviceDescriptionController.setConfig({
adapter
});
if (!segmentBaseController) {
segmentBaseController = SegmentBaseController(context).getInstance({
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
errHandler: errHandler,
baseURLController: baseURLController,
events: Events,
eventBus: eventBus,
debug: debug,
boxParser: BoxParser(context).getInstance(),
errors: Errors
});
}
// configure controllers
mediaController.setConfig({
domStorage,
settings,
mediaPlayerModel,
customParametersModel,
videoModel
});
mediaPlayerModel.setConfig({
playbackController,
serviceDescriptionController
});
contentSteeringController.setConfig({
adapter,
errHandler,
dashMetrics,
mediaPlayerModel,
manifestModel,
serviceDescriptionController,
throughputController,
eventBus
})
restoreDefaultUTCTimingSources();
setAutoPlay(autoPlay !== undefined ? autoPlay : true);
// Detect and initialize offline module to support offline contents playback
_detectOffline();
}
if (view) {
attachView(view);
}
if (source) {
attachSource(source, startTime);
}
logger.info('[dash.js ' + getVersion() + '] ' + 'MediaPlayer has been initialized');
}
/**
* Sets the MPD source and the video element to null. You can also reset the MediaPlayer by
* calling attachSource with a new source file.
*
* This call does not destroy the MediaPlayer. To destroy the MediaPlayer and free all of its
* memory, call destroy().
*
* @memberof module:MediaPlayer
* @instance
*/
function reset() {
attachSource(null);
attachView(null);
protectionData = null;
if (protectionController) {
protectionController.reset();
protectionController = null;
}
if (metricsReportingController) {
metricsReportingController.reset();
metricsReportingController = null;
}
if (customParametersModel) {
customParametersModel.reset();
}
settings.reset();
if (offlineController) {
offlineController.reset();
offlineController = null;
}
}
/**
* Completely destroys the media player and frees all memory.
*
* @memberof module:MediaPlayer
* @instance
*/
function destroy() {
reset();
FactoryMaker.deleteSingletonInstances(context);
}
/**
* The ready state of the MediaPlayer based on both the video element and MPD source being defined.
*
* @returns {boolean} The current ready state of the MediaPlayer
* @see {@link module:MediaPlayer#attachView attachView()}
* @see {@link module:MediaPlayer#attachSource attachSource()}
* @memberof module:MediaPlayer
* @instance
*/
function isReady() {
return (!!source && !!videoModel.getElement());
}
/**
* Use the on method to listen for public events found in MediaPlayer.events. {@link MediaPlayerEvents}
*
* @param {string} type - {@link MediaPlayerEvents}
* @param {Function} listener - callback method when the event fires.
* @param {Object} scope - context of the listener so it can be removed properly.
* @param {Object} options - object to define various options such as priority and mode
* @memberof module:MediaPlayer
* @instance
*/
function on(type, listener, scope, options) {
eventBus.on(type, listener, scope, options);
}
/**
* Use the off method to remove listeners for public events found in MediaPlayer.events. {@link MediaPlayerEvents}
*
* @param {string} type - {@link MediaPlayerEvents}
* @param {Function} listener - callback method when the event fires.
* @param {Object} scope - context of the listener so it can be removed properly.
* @memberof module:MediaPlayer
* @instance
*/
function off(type, listener, scope) {
eventBus.off(type, listener, scope);
}
/**
* Use this method to trigger an event via the eventBus {@link MediaPlayerEvents}
*
* @param {string} type - {@link MediaPlayerEvents}
* @param {object} payload - Payload of the event
* @param {Object} filters - Define a "streamId" and/or a "mediaType" for which this event is valid, e.g. {streamId, mediaType}
* @memberof module:MediaPlayer
* @instance
*/
function trigger(type, payload, filters) {
eventBus.trigger(type, payload, filters);
}
/**
* Current version of Dash.js
* @returns {string} the current dash.js version string.
* @memberof module:MediaPlayer
* @instance
*/
function getVersion() {
return getVersionString();
}
/**
* Use this method to access the dash.js logging class.
*
* @returns {Debug}
* @memberof module:MediaPlayer
* @instance
*/
function getDebug() {
return debug;
}
/*
---------------------------------------------------------------------------
PLAYBACK FUNCTIONS
---------------------------------------------------------------------------
*/
/**
* Causes the player to begin streaming the media as set by the {@link module:MediaPlayer#attachSource attachSource()}
* method in preparation for playing. It specifically does not require a view to be attached with {@link module:MediaPlayer#attachSource attachView()} to begin preloading.
* When a view is attached after preloading, the buffered data is transferred to the attached mediaSource buffers.
*
* @see {@link module:MediaPlayer#attachSource attachSource()}
* @see {@link module:MediaPlayer#attachView attachView()}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~SOURCE_NOT_ATTACHED_ERROR SOURCE_NOT_ATTACHED_ERROR} if called before attachSource function
* @instance
*/
function preload() {
if (videoModel.getElement() || streamingInitialized) {
return;
}
if (source) {
_initializePlayback(providedStartTime);
} else {
throw SOURCE_NOT_ATTACHED_ERROR;
}
}
/**
* The play method initiates playback of the media defined by the {@link module:MediaPlayer#attachSource attachSource()} method.
* This method will call play on the native Video Element.
*
* @see {@link module:MediaPlayer#attachSource attachSource()}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function play() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
if (!autoPlay || (isPaused() && playbackInitialized)) {
playbackController.play(true);
}
}
/**
* This method will call pause on the native Video Element.
*
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function pause() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
playbackController.pause();
}
/**
* Returns a Boolean that indicates whether the Video Element is paused.
* @return {boolean}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function isPaused() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
return playbackController.isPaused();
}
/**
* Sets the currentTime property of the attached video element. If it is a live stream with a
* timeShiftBufferLength, then the DVR window offset will be automatically calculated.
*
* @param {number} value - A relative time, in seconds, based on the return value of the {@link module:MediaPlayer#duration duration()} method is expected.
* For dynamic streams duration() returns DVRWindow.end - DVRWindow.start. Consequently, the value provided to this function should be relative to DVRWindow.start.
* @see {@link module:MediaPlayer#getDvrSeekOffset getDvrSeekOffset()}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with an invalid argument, not number type or is NaN.
* @memberof module:MediaPlayer
* @instance
*/
function seek(value) {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
checkParameterType(value, 'number');
if (isNaN(value)) {
throw Constants.BAD_ARGUMENT_ERROR;
}
if (value < 0) {
value = 0;
}
let s = playbackController.getIsDynamic() ? getDvrSeekOffset(value) : value;
// For VoD limit the seek to the duration of the content
const videoElement = getVideoElement();
if (!playbackController.getIsDynamic() && videoElement.duration) {
s = Math.min(videoElement.duration, s);
}
playbackController.seek(s, false, false, true);
}
/**
* Sets the currentTime property of the attached video element. Compared to the seek() function this function does not add the DVR window offset. Instead, it takes a presentation time relative to the availability start time.
* For VoD this function behaves similar to the seek() function.
* @param {number} value - A presentation time in seconds
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with an invalid argument, not number type or is NaN.
* @memberof module:MediaPlayer
* @instance
*/
function seekToPresentationTime(seektime) {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
checkParameterType(seektime, 'number');
if (isNaN(seektime)) {
throw Constants.BAD_ARGUMENT_ERROR;
}
if (seektime < 0) {
seektime = 0;
}
// For VoD limit the seek to the duration of the content
const videoElement = getVideoElement();
if (!playbackController.getIsDynamic() && videoElement.duration) {
seektime = Math.min(videoElement.duration, seektime);
}
// For live, take live delay into account
if (playbackController.getIsDynamic()) {
const type = streamController && streamController.hasVideoTrack() ? Constants.VIDEO : Constants.AUDIO;
let metric = dashMetrics.getCurrentDVRInfo(type);
if (!metric) {
return;
}
seektime = _adjustSeekTimeBasedOnLiveDelay(seektime, metric)
if (seektime < metric.range.start) {
seektime = metric.range.start
}
}
playbackController.seek(seektime, false, false, true);
}
/**
* Seeks back to the original live edge (live edge as calculated at playback start). Only applies to live streams, for VoD streams this call will be ignored.
*/
function seekToOriginalLive() {
if (!playbackInitialized || !isDynamic()) {
return;
}
playbackController.seekToOriginalLive();
}
/**
* Returns a Boolean that indicates whether the media is in the process of seeking to a new position.
* @return {boolean}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function isSeeking() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
return playbackController.isSeeking();
}
/**
* Returns a Boolean that indicates whether the media is in the process of dynamic.
* @return {boolean}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function isDynamic() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
return playbackController.getIsDynamic();
}
/**
* Returns a boolean that indicates whether the player is operating in low latency mode.
* @return {boolean}
* @memberof module:MediaPlayer
* @instance
*/
function getLowLatencyModeEnabled() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
return playbackController.getLowLatencyModeEnabled();
}
/**
* Use this method to set the native Video Element's playback rate.
* @param {number} value
* @memberof module:MediaPlayer
* @instance
*/
function setPlaybackRate(value) {
getVideoElement().playbackRate = value;
}
/**
* Returns the current playback rate.
* @returns {number}
* @memberof module:MediaPlayer
* @instance
*/
function getPlaybackRate() {
return getVideoElement().playbackRate;
}
/**
* Use this method to set the native Video Element's muted state. Takes a Boolean that determines whether audio is muted. true if the audio is muted and false otherwise.
* @param {boolean} value
* @memberof module:MediaPlayer
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with an invalid argument, not boolean type.
* @instance
*/
function setMute(value) {
checkParameterType(value, 'boolean');
getVideoElement().muted = value;
}
/**
* A Boolean that determines whether audio is muted.
* @returns {boolean}
* @memberof module:MediaPlayer
* @instance
*/
function isMuted() {
return getVideoElement().muted;
}
/**
* A double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest).
* @param {number} value
* @memberof module:MediaPlayer
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with an invalid argument, not number type, or is NaN or not between 0 and 1.
* @instance
*/
function setVolume(value) {
if (typeof value !== 'number' || isNaN(value) || value < 0.0 || value > 1.0) {
throw Constants.BAD_ARGUMENT_ERROR;
}
getVideoElement().volume = value;
}
/**
* Returns the current audio volume, from 0.0 (silent) to 1.0 (loudest).
* @returns {number}
* @memberof module:MediaPlayer
* @instance
*/
function getVolume() {
return getVideoElement().volume;
}
/**
* The length of the buffer for a given media type, in seconds. Valid media
* types are "video", "audio" and "text". If no type is passed
* in, then the minimum of video, audio and text buffer length is
* returned. NaN is returned if an invalid type is requested, the
* presentation does not contain that type, or if no arguments are passed
* and the presentation does not include any adaption sets of valid media
* type.
*
* @param {MediaType} type - 'video', 'audio' or 'text'
* @returns {number} The length of the buffer for the given media type, in
* seconds, or NaN
* @memberof module:MediaPlayer
* @instance
*/
function getBufferLength(type) {
const types = [Constants.VIDEO, Constants.AUDIO, Constants.TEXT];
if (!type) {
const buffer = types.map(
t => getTracksFor(t).length > 0 ? getDashMetrics().getCurrentBufferLevel(t) : Number.MAX_VALUE
).reduce(
(p, c) => Math.min(p, c)
);
return buffer === Number.MAX_VALUE ? NaN : buffer;
} else {
if (types.indexOf(type) !== -1) {
const buffer = getDashMetrics().getCurrentBufferLevel(type);
return buffer ? buffer : NaN;
} else {
logger.warn('getBufferLength requested for invalid type');
return NaN;
}
}
}
/**
* This method should only be used with a live stream that has a valid timeShiftBufferLength (DVR Window).
* NOTE - If you do not need the raw offset value (i.e. media analytics, tracking, etc) consider using the {@link module:MediaPlayer#seek seek()} method
* which will calculate this value for you and set the video element's currentTime property all in one simple call.
*
* @param {number} value - A relative time, in seconds, based on the return value of the {@link module:MediaPlayer#duration duration()} method is expected.
* @returns {number} A value that is relative the available range within the timeShiftBufferLength (DVR Window).
* @see {@link module:MediaPlayer#seek seek()}
* @memberof module:MediaPlayer
* @instance
*/
function getDvrSeekOffset(value) {
const type = streamController && streamController.hasVideoTrack() ? Constants.VIDEO : Constants.AUDIO;
let metric = dashMetrics.getCurrentDVRInfo(type);
if (!metric) {
return 0;
}
let val = metric.range.start + value;
return _adjustSeekTimeBasedOnLiveDelay(val, metric);
}
function _adjustSeekTimeBasedOnLiveDelay(seektime, metric) {
let liveDelay = playbackController.getOriginalLiveDelay();
if (seektime > (metric.range.end - liveDelay)) {
seektime = metric.range.end - liveDelay;
}
return seektime;
}
/**
* Returns the target live delay
* @returns {number} The target live delay
* @memberof module:MediaPlayer
* @instance
*/
function getTargetLiveDelay() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
return playbackController.getOriginalLiveDelay();
}
/**
* Current playhead time in seconds.
*
* If called with no arguments then the returned value is the current time of the video element.
* However, if a period ID is supplied then time is relative to the start of that period, or is null if there is no such period id in the manifest.
*
* @param {string} periodId - The ID of a period that the returned playhead time must be relative to the start of. If undefined, then playhead time is relative to the first period or the AST.
* @returns {number} The current playhead time of the media, or null.
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function time(periodId = '') {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
let t = getVideoElement().currentTime;
if (periodId !== '') {
t = streamController.getTimeRelativeToStreamId(t, periodId);
}
return t;
}
/**
* Returns the current playhead time relative to the start of the DVR window.
* For VoD this method returns the same value as time()
* @returns {number} The current playhead time of the media relative to the start of the DVR window
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function timeInDvrWindow() {
Iif (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
if (!playbackController.getIsDynamic()) {
return time()
}
let t = getVideoElement().currentTime;
const type = streamController && streamController.hasVideoTrack() ? Constants.VIDEO : Constants.AUDIO;
let metric = dashMetrics.getCurrentDVRInfo(type);
t = (metric === null || t === 0) ? 0 : Math.max(0, (t - metric.range.start));
return t
}
/**
* Returns information about the current DVR window including the start time, the end time, the window size.
* @returns {{startAsUtc: (*|number), size: number, endAsUtc: (*|number), start, end}|{}}
*/
function getDvrWindow() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
const type = streamController && streamController.hasVideoTrack() ? Constants.VIDEO : Constants.AUDIO;
let metric = dashMetrics.getCurrentDVRInfo(type);
if (!metric) {
return {}
}
let offset = 0;
const isDynamic = playbackController.getIsDynamic();
if (isDynamic) {
offset = metric.manifestInfo.availableFrom.getTime() / 1000;
}
return {
start: metric.range.start,
end: metric.range.end,
startAsUtc: isDynamic ? offset + metric.range.start : NaN,
endAsUtc: isDynamic ? offset + metric.range.end : NaN,
size: metric.range.end - metric.range.start
}
}
/**
* Total duration of the media in seconds.
*
* @returns {number} The total duration of the media. For a dynamic stream this will return DVRWindow.end - DVRWindow.start
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function duration() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
let d = getVideoElement().duration;
if (playbackController.getIsDynamic()) {
const type = streamController && streamController.hasVideoTrack() ? Constants.VIDEO : Constants.AUDIO;
let metric = dashMetrics.getCurrentDVRInfo(type);
d = metric ? (metric.range.end - metric.range.start) : 0;
}
return d;
}
/**
* Use this method to get the current playhead time as an absolute value in seconds since midnight UTC, Jan 1 1970.
* Note - this property only has meaning for live streams and is NaN for VoD content. If called before play() has begun, it will return a value of NaN.
*
* @returns {number} The current playhead time as UTC timestamp.
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function timeAsUTC() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
if (!playbackController.getIsDynamic() || time() < 0) {
return NaN
}
const type = streamController && streamController.hasVideoTrack() ? Constants.VIDEO : Constants.AUDIO;
let metric = dashMetrics.getCurrentDVRInfo(type);
let availabilityStartTime,
utcValue;
if (!metric) {
return 0;
}
availabilityStartTime = metric.manifestInfo.availableFrom.getTime() / 1000;
utcValue = availabilityStartTime + time()
return utcValue;
}
/*
---------------------------------------------------------------------------
MEDIA PLAYER CONFIGURATION
---------------------------------------------------------------------------
*/
/**
* <p>Set to false to prevent stream from auto-playing when the view is attached.</p>
*
* @param {boolean} value
* @default true
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#attachView attachView()}
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with an invalid argument, not boolean type.
* @instance
*
*/
function setAutoPlay(value) {
checkParameterType(value, 'boolean');
autoPlay = value;
}
/**
* @returns {boolean} The current autoPlay state.
* @memberof module:MediaPlayer
* @instance
*/
function getAutoPlay() {
return autoPlay;
}
/**
* @memberof module:MediaPlayer
* @instance
* @returns {number|NaN} Current live stream latency in seconds. It is the difference between now time and time position at the playback head.
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
*/
function getCurrentLiveLatency() {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
if (!playbackInitialized) {
return NaN;
}
return playbackController.getCurrentLiveLatency();
}
/**
* Add a custom ABR Rule
* Rule will be apply on next stream if a stream is being played
*
* @param {string} type - rule type (one of ['qualitySwitchRules','abandonFragmentRules'])
* @param {string} rulename - name of rule (used to identify custom rule). If one rule of same name has been added, then existing rule will be updated
* @param {object} rule - the rule object instance
* @memberof module:MediaPlayer
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with invalid arguments.
* @instance
*/
function addABRCustomRule(type, rulename, rule) {
customParametersModel.addAbrCustomRule(type, rulename, rule);
}
/**
* Remove a custom ABR Rule
*
* @param {string} rulename - name of the rule to be removed
* @memberof module:MediaPlayer
* @instance
*/
function removeABRCustomRule(rulename) {
customParametersModel.removeAbrCustomRule(rulename);
}
/**
* Remove all ABR custom rules
* @memberof module:MediaPlayer
* @instance
*/
function removeAllABRCustomRule() {
customParametersModel.removeAllAbrCustomRule();
}
/**
* Returns all ABR custom rules
* @return {Array}
*/
function getABRCustomRules() {
return customParametersModel.getAbrCustomRules();
}
/**
* <p>Allows you to set a scheme and server source for UTC live edge detection for dynamic streams.
* If UTCTiming is defined in the manifest, it will take precedence over any time source manually added.</p>
* <p>If you have exposed the Date header, use the method {@link module:MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}.
* This will allow the date header on the manifest to be used instead of a time server</p>
* @param {string} schemeIdUri - <ul>
* <li>urn:mpeg:dash:utc:http-head:2014</li>
* <li>urn:mpeg:dash:utc:http-xsdate:2014</li>
* <li>urn:mpeg:dash:utc:http-iso:2014</li>
* <li>urn:mpeg:dash:utc:direct:2014</li>
* </ul>
* <p>Some specs referencing early ISO23009-1 drafts incorrectly use
* 2012 in the URI, rather than 2014. support these for now.</p>
* <ul>
* <li>urn:mpeg:dash:utc:http-head:2012</li>
* <li>urn:mpeg:dash:utc:http-xsdate:2012</li>
* <li>urn:mpeg:dash:utc:http-iso:2012</li>
* <li>urn:mpeg:dash:utc:direct:2012</li>
* </ul>
* @param {string} value - Path to a time source.
* @default
* <ul>
* <li>schemeIdUri:urn:mpeg:dash:utc:http-xsdate:2014</li>
* <li>value:http://time.akamai.com/?iso&ms/li>
* </ul>
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#removeUTCTimingSource removeUTCTimingSource()}
* @instance
*/
function addUTCTimingSource(schemeIdUri, value) {
customParametersModel.addUTCTimingSource(schemeIdUri, value);
}
/**
* <p>Allows you to remove a UTC time source. Both schemeIdUri and value need to match the Dash.vo.UTCTiming properties in order for the
* entry to be removed from the array</p>
* @param {string} schemeIdUri - see {@link module:MediaPlayer#addUTCTimingSource addUTCTimingSource()}
* @param {string} value - see {@link module:MediaPlayer#addUTCTimingSource addUTCTimingSource()}
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with invalid arguments, schemeIdUri and value are not string type.
* @instance
*/
function removeUTCTimingSource(schemeIdUri, value) {
customParametersModel.removeUTCTimingSource(schemeIdUri, value);
}
/**
* <p>Allows you to clear the stored array of time sources.</p>
* <p>Example use: If you have exposed the Date header, calling this method
* will allow the date header on the manifest to be used instead of the time server.</p>
* <p>Example use: Calling this method, assuming there is not an exposed date header on the manifest, will default back
* to using a binary search to discover the live edge</p>
*
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#restoreDefaultUTCTimingSources restoreDefaultUTCTimingSources()}
* @instance
*/
function clearDefaultUTCTimingSources() {
customParametersModel.clearDefaultUTCTimingSources();
}
/**
* <p>Allows you to restore the default time sources after calling {@link module:MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}</p>
*
* @default
* <ul>
* <li>schemeIdUri:urn:mpeg:dash:utc:http-xsdate:2014</li>
* <li>value:http://time.akamai.com/?iso&ms</li>
* </ul>
*
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#addUTCTimingSource addUTCTimingSource()}
* @instance
*/
function restoreDefaultUTCTimingSources() {
customParametersModel.restoreDefaultUTCTimingSources();
}
/**
* Returns the average latency computed in the ThroughputController in milliseconds
*
* @param {MediaType} type
* @param {string} calculationMode
* @param {number} sampleSize
* @return {number} value
* @memberof module:MediaPlayer
* @instance
*/
function getAverageLatency(type = Constants.VIDEO, calculationMode = null, sampleSize = NaN) {
return throughputController ? throughputController.getAverageLatency(type, calculationMode, sampleSize) : 0;
}
/**
* Returns the average throughput computed in the ThroughputController in kbit/s
*
* @param {MediaType} type
* @param {string} calculationMode
* @param {number} sampleSize
* @return {number} value
* @memberof module:MediaPlayer
* @instance
*/
function getAverageThroughput(type = Constants.VIDEO, calculationMode = null, sampleSize = NaN) {
return throughputController ? throughputController.getAverageThroughput(type, calculationMode, sampleSize) : 0;
}
/**
* Returns the safe average throughput computed in the ThroughputController in kbit/s. The safe average throughput is the average throughput multiplied by bandwidthSafetyFactor
*
* @param {MediaType} type
* @param {string} calculationMode
* @param {number} sampleSize
* @return {number} value
* @memberof module:MediaPlayer
* @instance
*/
function getSafeAverageThroughput(type = Constants.VIDEO, calculationMode = null, sampleSize = NaN) {
return throughputController ? throughputController.getSafeAverageThroughput(type, calculationMode, sampleSize) : 0;
}
/**
* Returns the raw throughput data without calculating the average. This can be used to calculate the current throughput yourself.
*
* @param {MediaType} type
* @return {Array} value
* @memberof module:MediaPlayer
* @instance
*/
function getRawThroughputData(type = Constants.VIDEO) {
return throughputController ? throughputController.getRawThroughputData(type) : [];
}
/**
* Sets whether withCredentials on XHR requests for a particular request
* type is true or false
*
* @default false
* @param {string} type - one of HTTPRequest.*_TYPE
* @param {boolean} value
* @memberof module:MediaPlayer
* @instance
*/
function setXHRWithCredentialsForType(type, value) {
customParametersModel.setXHRWithCredentialsForType(type, value);
}
/**
* Gets whether withCredentials on XHR requests for a particular request
* type is true or false
*
* @param {string} type - one of HTTPRequest.*_TYPE
* @return {boolean}
* @memberof module:MediaPlayer
* @instance
*/
function getXHRWithCredentialsForType(type) {
return customParametersModel.getXHRWithCredentialsForType(type);
}
/*
---------------------------------------------------------------------------
OFFLINE
---------------------------------------------------------------------------
*/
/**
* Detects if Offline is included and returns an instance of OfflineController.js
* @memberof module:MediaPlayer
* @instance
*/
function getOfflineController() {
return _detectOffline();
}
/*
---------------------------------------------------------------------------
METRICS
---------------------------------------------------------------------------
*/
/**
* Returns the DashMetrics.js Module. You use this Module to get access to all the public metrics
* stored in dash.js
*
* @see {@link module:DashMetrics}
* @returns {Object}
* @memberof module:MediaPlayer
* @instance
*/
function getDashMetrics() {
return dashMetrics;
}
/*
---------------------------------------------------------------------------
TEXT MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* Enable/disable text
* When enabling text, dash will choose the previous selected text track
*
* @param {boolean} enable - true to enable text, false otherwise (same as setTextTrack(-1))
* @memberof module:MediaPlayer
* @instance
*/
function enableText(enable) {
const activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return false;
}
return textController.enableText(activeStreamInfo.id, enable);
}
/**
* Enable/disable text
* When enabling dash will keep downloading and process fragmented text tracks even if all tracks are in mode "hidden"
*
* @param {boolean} enable - true to enable text streaming even if all text tracks are hidden.
* @memberof module:MediaPlayer
* @instance
*/
function enableForcedTextStreaming(enable) {
const activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return false;
}
return textController.enableForcedTextStreaming(enable);
}
/**
* Return if text is enabled
*
* @return {boolean} return true if text is enabled, false otherwise
* @memberof module:MediaPlayer
* @instance
*/
function isTextEnabled() {
const activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return false;
}
return textController.isTextEnabled(activeStreamInfo);
}
/**
* Use this method to change the current text track for both external time text files and fragmented text tracks. There is no need to
* set the track mode on the video object to switch a track when using this method.
* @param {number} idx - Index of track based on the order of the order the tracks are added Use -1 to disable all tracks. (turn captions off). Use module:MediaPlayer#dashjs.MediaPlayer.events.TEXT_TRACK_ADDED.
* @see {@link MediaPlayerEvents#event:TEXT_TRACK_ADDED dashjs.MediaPlayer.events.TEXT_TRACK_ADDED}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function setTextTrack(idx) {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
const activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return;
}
textController.setTextTrack(activeStreamInfo.id, idx);
}
function getCurrentTextTrackIndex() {
let idx = NaN;
const activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return;
}
idx = textController.getCurrentTrackIdx(activeStreamInfo.id);
return idx;
}
/*
---------------------------------------------------------------------------
VIDEO ELEMENT MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* Returns instance of Video Element that was attached by calling attachView()
* @returns {Object}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~ELEMENT_NOT_ATTACHED_ERROR ELEMENT_NOT_ATTACHED_ERROR} if called before attachView function
* @instance
*/
function getVideoElement() {
if (!videoModel.getElement()) {
throw ELEMENT_NOT_ATTACHED_ERROR;
}
return videoModel.getElement();
}
/**
* Use this method to attach an HTML5 VideoElement for dash.js to operate upon.
*
* @param {Object} element - An HTMLMediaElement that has already been defined in the DOM (or equivalent stub).
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
* @instance
*/
function attachView(element) {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
videoModel.setElement(element);
if (element) {
_detectProtection();
_detectMetricsReporting();
_detectMss();
if (streamController) {
streamController.switchToVideoElement(providedStartTime);
}
}
if (playbackInitialized) { //Reset if we have been playing before, so this is a new element.
_resetPlaybackControllers();
_resetPlaybackSessionSpecificSettings();
}
_initializePlayback(providedStartTime);
}
/**
* Returns instance of Div that was attached by calling attachTTMLRenderingDiv()
* @returns {Object}
* @memberof module:MediaPlayer
* @instance
*/
function getTTMLRenderingDiv() {
return videoModel ? videoModel.getTTMLRenderingDiv() : null;
}
/**
* Use this method to attach an HTML5 div for dash.js to render rich TTML subtitles.
*
* @param {HTMLDivElement} div - An unstyled div placed after the video element. It will be styled to match the video size and overlay z-order.
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~ELEMENT_NOT_ATTACHED_ERROR ELEMENT_NOT_ATTACHED_ERROR} if called before attachView function
* @instance
*/
function attachTTMLRenderingDiv(div) {
Iif (!videoModel.getElement()) {
throw ELEMENT_NOT_ATTACHED_ERROR;
}
videoModel.setTTMLRenderingDiv(div);
}
function attachVttRenderingDiv(div) {
if (!videoModel.getElement()) {
throw ELEMENT_NOT_ATTACHED_ERROR;
}
videoModel.setVttRenderingDiv(div);
}
/*
---------------------------------------------------------------------------
QUALITY AND TRACK MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* Gets the current download quality for media type video, audio or images. For video and audio types the ABR
* rules update this value before every new download unless autoSwitchBitrate is set to false. For 'image'
* type, thumbnails, there is no ABR algorithm and quality is set manually.
*
* @param {MediaType} type - 'video', 'audio' or 'image' (thumbnails)
* @returns {Representation | null} the quality index, 0 corresponding to the lowest bitrate
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#getCurrentRepresentationForType getCurrentRepresentationForType()}
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getCurrentRepresentationForType(type) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
if (type !== Constants.IMAGE && type !== Constants.VIDEO && type !== Constants.AUDIO) {
return null;
}
const activeStream = getActiveStream();
if (!activeStream) {
return null;
}
if (type === Constants.IMAGE) {
const thumbnailController = activeStream.getThumbnailController();
return !thumbnailController ? -1 : thumbnailController.getCurrentTrack();
}
return activeStream.getCurrentRepresentationForType(type);
}
/**
* Sets the current quality for media type instead of letting the ABR Heuristics automatically select it.
* This value will be overwritten by the ABR rules unless autoSwitchBitrate is set to false.
*
* @param {MediaType} type - 'video', 'audio' or 'image'
* @param {number} id , The ID of the Representation
* @param {boolean} forceReplace - true if segments have to be replaced by segments of the new quality
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function setRepresentationForTypeById(type, id, forceReplace = false) {
if (type !== Constants.IMAGE && type !== Constants.VIDEO && type !== Constants.AUDIO) {
return;
}
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
const activeStream = getActiveStream();
if (!activeStream) {
return;
}
if (type === Constants.IMAGE) {
const thumbnailController = activeStream.getThumbnailController();
if (thumbnailController) {
thumbnailController.setTrackById(id);
}
} else {
const representation = activeStream.getRepresentationForTypeById(type, id);
if (representation) {
abrController.manuallySetPlaybackQuality(type, streamController.getActiveStreamInfo(), representation, { forceReplace });
}
}
}
/**
* Sets the current quality for media type instead of letting the ABR Heuristics automatically select it.
* This value will be overwritten by the ABR rules unless autoSwitchBitrate is set to false.
* Note that you need to specify a relative index based on the position of the target entry in the return value of getRepresentationsByType().
* Do NOT use representation.absoluteIndex here as this index was assigned prior to applying any filter function. If you want to select a specific representation then use setRepresentationForTypeById() instead.
*
* @param {MediaType} type - 'video', 'audio' or 'image'
* @param {number} index - the quality index, 0 corresponding to the lowest possible index
* @param {boolean} forceReplace - true if segments have to be replaced by segments of the new quality
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function setRepresentationForTypeByIndex(type, index, forceReplace = false) {
if (type !== Constants.IMAGE && type !== Constants.VIDEO && type !== Constants.AUDIO) {
return;
}
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
const activeStream = getActiveStream();
if (!activeStream) {
return;
}
if (type === Constants.IMAGE) {
const thumbnailController = activeStream.getThumbnailController();
if (thumbnailController) {
thumbnailController.setTrackByIndex(index);
}
} else {
const representation = activeStream.getRepresentationForTypeByIndex(type, index);
if (representation) {
abrController.manuallySetPlaybackQuality(type, streamController.getActiveStreamInfo(), representation, { forceReplace });
}
}
}
/**
* @param {MediaType} type
* @param {string} streamId
* @returns {Array}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getRepresentationsByType(type, streamId = null) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
let stream = streamId ? streamController.getStreamById(streamId) : getActiveStream();
return stream ? stream.getRepresentationsByType(type) : [];
}
/**
* This method returns the list of all available streams from a given manifest
* @param {Object} manifest
* @returns {Array} list of {@link StreamInfo}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getStreamsFromManifest(manifest) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
return adapter.getStreamsInfo(manifest);
}
/**
* This method returns the list of all available tracks for a given media type
* @param {MediaType} type
* @returns {Array} list of {@link MediaInfo}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getTracksFor(type) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
let streamInfo = streamController.getActiveStreamInfo();
Iif (!streamInfo) {
return [];
}
const tracks = mediaController.getTracksFor(type, streamInfo.id);
return tracks.filter((track) => {
return protectionController ? protectionController.areKeyIdsUsable(track.normalizedKeyIds) : true
})
}
/**
* This method returns the list of all available tracks for a given media type and streamInfo from a given manifest
* @param {MediaType} type
* @param {Object} manifest
* @param {Object} streamInfo
* @returns {Array} list of {@link MediaInfo}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getTracksForTypeFromManifest(type, manifest, streamInfo) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
streamInfo = streamInfo || adapter.getStreamsInfo(manifest, 1)[0];
return streamInfo ? adapter.getAllMediaInfoForType(streamInfo, type, manifest) : [];
}
/**
* @param {MediaType} type
* @returns {Object|null} {@link MediaInfo}
*
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getCurrentTrackFor(type) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
let streamInfo = streamController.getActiveStreamInfo();
if (streamInfo) {
return mediaController.getCurrentTrackFor(type, streamInfo.id);
}
return null
}
/**
* This method allows to set media settings that will be used to pick the initial track. Format of the settings
* is following: <br />
* {lang: langValue (can be either a string primitive, a string object, or a RegExp object to match),
* index: indexValue,
* viewpoint: viewpointValue (object:{schemeIdUri,value} or value-primitive),
* audioChannelConfiguration: audioChannelConfigurationValue (object:{schemeIdUri,value} or value-primitive (assumes schemeIdUri='urn:mpeg:mpegB:cicp:ChannelConfiguration')),
* accessibility: accessibilityValue (object:{schemeIdUri,value} or value-primitive (assumes schemeIdUri='urn:mpeg:dash:role:2011')),
* role: roleValue (object:{schemeIdUri,value} or value-primitive (assumes schemeIdUri='urn:mpeg:dash:role:2011'))
* }
*
* @param {MediaType} type
* @param {Object} value
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
* @instance
*/
function setInitialMediaSettingsFor(type, value) {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
let sanitizedValue = _sanitizeSettings(value);
mediaController.setInitialSettings(type, sanitizedValue);
}
/**
* This method returns media settings that is used to pick the initial track. Format of the settings
* is following:
* {lang: langValue,
* index: indexValue,
* viewpoint: viewpointValue,
* audioChannelConfiguration: audioChannelConfigurationValue,
* accessibility: accessibilityValue,
* role: roleValue}
* @param {MediaType} type
* @returns {Object}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
* @instance
*/
function getInitialMediaSettingsFor(type) {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
return mediaController.getInitialSettings(type);
}
/**
* @param {MediaInfo} track - instance of {@link MediaInfo}
* @param {boolean} [noSettingsSave] - specify if settings from the track must not be saved for incoming track selection
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function setCurrentTrack(track, noSettingsSave = false) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
const canUseTrack = protectionController ? protectionController.areKeyIdsUsable(track.normalizedKeyIds) : true
Iif (!canUseTrack) {
logger.error(`Can not switch to track with index ${track.index} because key is not usable`);
return
}
mediaController.setTrack(track, { noSettingsSave });
}
/*
---------------------------------------------------------------------------
Custom filter and callback functions
---------------------------------------------------------------------------
*/
/**
* Registers a custom capabilities filter. This enables application to filter representations to use.
* The provided callback function shall return either a boolean or a promise resolving to a boolean based on whether or not to use the representation.
* The filters are applied in the order they are registered.
* @param {function} filter - the custom capabilities filter callback
* @memberof module:MediaPlayer
* @instance
*/
function registerCustomCapabilitiesFilter(filter) {
customParametersModel.registerCustomCapabilitiesFilter(filter);
}
/**
* Unregisters a custom capabilities filter.
* @param {function} filter - the custom capabilities filter callback
* @memberof module:MediaPlayer
* @instance
*/
function unregisterCustomCapabilitiesFilter(filter) {
customParametersModel.unregisterCustomCapabilitiesFilter(filter);
}
/**
* Registers a custom initial track selection function. Only one function is allowed. Calling this method will overwrite a potentially existing function.
* @param {function} customFunc - the custom function that returns the initial track
*/
function setCustomInitialTrackSelectionFunction(customFunc) {
customParametersModel.setCustomInitialTrackSelectionFunction(customFunc);
}
/**
* Resets the custom initial track selection
*/
function resetCustomInitialTrackSelectionFunction() {
customParametersModel.resetCustomInitialTrackSelectionFunction(null);
}
/**
* Adds an external subtitle file. The provided externalSubtitle must be an instance of the ExternalSubtitle class.
* @param {ExternalSubtitle} externalSubtitle
* @memberof module:MediaPlayer
* @instance
*/
function addExternalSubtitle(externalSubtitle) {
if (!(externalSubtitle instanceof ExternalSubtitle)) {
logger.error('Invalid external subtitle object. Must be an instance of dashjs.ExternalSubtitle');
}
customParametersModel.addExternalSubtitle(externalSubtitle);
}
/**
* Removes an external subtitle file by its ID.
* @param {string} id
*/
function removeExternalSubtitleById(id) {
customParametersModel.removeExternalSubtitleById(id);
}
/**
* Removes an external subtitle file by its url.
* @param {string} url
*/
function removeExternalSubtitleByUrl(url) {
customParametersModel.removeExternalSubtitleByUrl(url);
}
/**
* Returns all external subtitles
*/
function getExternalSubtitles() {
customParametersModel.getExternalSubtitles();
}
/**
* Adds a request interceptor. This enables application to monitor, manipulate, overwrite any request parameter and/or request data.
* The provided callback function shall return a promise with updated request that shall be resolved once the process of the request is completed.
* The interceptors are applied in the order they are added.
* @param {function} interceptor - the request interceptor callback
* @memberof module:MediaPlayer
* @instance
*/
function addRequestInterceptor(interceptor) {
customParametersModel.addRequestInterceptor(interceptor);
}
/**
* Removes a request interceptor.
* @param {function} interceptor - the request interceptor callback
* @memberof module:MediaPlayer
* @instance
*/
function removeRequestInterceptor(interceptor) {
customParametersModel.removeRequestInterceptor(interceptor);
}
/**
* Adds a response interceptor. This enables application to monitor, manipulate, overwrite the response data
* The provided callback function shall return a promise with updated response that shall be resolved once the process of the response is completed.
* The interceptors are applied in the order they are added.
* @param {function} interceptor - the response interceptor
* @memberof module:MediaPlayer
* @instance
*/
function addResponseInterceptor(interceptor) {
customParametersModel.addResponseInterceptor(interceptor);
}
/**
* Removes a response interceptor.
* @param {function} interceptor - the request interceptor
* @memberof module:MediaPlayer
* @instance
*/
function removeResponseInterceptor(interceptor) {
customParametersModel.removeResponseInterceptor(interceptor);
}
/**
* Registers a license request filter. This enables application to manipulate/overwrite any request parameter and/or request data.
* The provided callback function shall return a promise that shall be resolved once the filter process is completed.
* The filters are applied in the order they are registered.
* @param {function} filter - the license request filter callback
* @memberof module:MediaPlayer
* @instance
*/
function registerLicenseRequestFilter(filter) {
customParametersModel.registerLicenseRequestFilter(filter);
}
/**
* Registers a license response filter. This enables application to manipulate/overwrite the response data
* The provided callback function shall return a promise that shall be resolved once the filter process is completed.
* The filters are applied in the order they are registered.
* @param {function} filter - the license response filter callback
* @memberof module:MediaPlayer
* @instance
*/
function registerLicenseResponseFilter(filter) {
customParametersModel.registerLicenseResponseFilter(filter);
}
/**
* Unregisters a license request filter.
* @param {function} filter - the license request filter callback
* @memberof module:MediaPlayer
* @instance
*/
function unregisterLicenseRequestFilter(filter) {
customParametersModel.unregisterLicenseRequestFilter(filter);
}
/**
* Unregisters a license response filter.
* @param {function} filter - the license response filter callback
* @memberof module:MediaPlayer
* @instance
*/
function unregisterLicenseResponseFilter(filter) {
customParametersModel.unregisterLicenseResponseFilter(filter);
}
/*
---------------------------------------------------------------------------
PROTECTION MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* Detects if Protection is included and returns an instance of ProtectionController.js
* @memberof module:MediaPlayer
* @instance
*/
function getProtectionController() {
return _detectProtection();
}
/**
* Will override dash.js protection controller.
* @param {ProtectionController} value - valid protection controller instance.
* @memberof module:MediaPlayer
* @instance
*/
function attachProtectionController(value) {
protectionController = value;
}
/**
* Sets Protection Data required to setup the Protection Module (DRM). Protection Data must
* be set before initializing MediaPlayer or, once initialized, before PROTECTION_CREATED event is fired.
* @see {@link module:MediaPlayer#initialize initialize()}
* @see {@link ProtectionEvents#event:PROTECTION_CREATED dashjs.Protection.events.PROTECTION_CREATED}
* @param {ProtectionDataSet} value - object containing
* property names corresponding to key system name strings and associated
* values being instances of.
* @memberof module:MediaPlayer
* @instance
*/
function setProtectionData(value) {
protectionData = value;
// Propagate changes in case StreamController is already created
if (streamController) {
streamController.setProtectionData(protectionData);
}
}
/*
---------------------------------------------------------------------------
THUMBNAILS MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* Provide the thumbnail at time position. This can be asynchronous, so you must provide a callback ro retrieve thumbnails informations
* @param {number} time - A relative time, in seconds, based on the return value of the {@link module:MediaPlayer#duration duration()} method is expected
* @param {function} callback - A Callback function provided when retrieving thumbnail the given time position. Thumbnail object is null in case there are is not a thumbnails representation or
* if it doesn't contain a thumbnail for the given time position.
* @memberof module:MediaPlayer
* @instance
*/
function provideThumbnail(time, callback) {
if (typeof callback !== 'function') {
return;
}
if (time < 0) {
callback(null);
return;
}
const s = playbackController.getIsDynamic() ? getDvrSeekOffset(time) : time;
const stream = streamController.getStreamForTime(s);
if (stream === null) {
callback(null);
return;
}
const thumbnailController = stream.getThumbnailController();
if (!thumbnailController) {
callback(null);
return;
}
return thumbnailController.provide(s, callback);
}
/*
---------------------------------------------------------------------------
TOOLS AND OTHERS FUNCTIONS
---------------------------------------------------------------------------
*/
/**
* Allows application to retrieve a manifest. Manifest loading is asynchronous and requires the app-provided callback function
*
* @param {string} url - url the manifest url
* @param {function} callback - A Callback function provided when retrieving manifests
* @memberof module:MediaPlayer
* @instance
*/
function retrieveManifest(url, callback) {
let manifestLoader = _createManifestLoader();
let self = this;
const handler = function (e) {
if (!e.error) {
callback(e.manifest);
} else {
callback(null, e.error);
}
eventBus.off(Events.INTERNAL_MANIFEST_LOADED, handler, self);
manifestLoader.reset();
};
eventBus.on(Events.INTERNAL_MANIFEST_LOADED, handler, self);
uriFragmentModel.initialize(url);
manifestLoader.load(url);
}
/**
* Returns the source string or manifest that was attached by calling attachSource()
* @returns {string | manifest}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~SOURCE_NOT_ATTACHED_ERROR SOURCE_NOT_ATTACHED_ERROR} if called before attachSource function
* @instance
*/
function getSource() {
if (!source) {
throw SOURCE_NOT_ATTACHED_ERROR;
}
return source;
}
/**
* Sets the source to a new manifest URL or object without reloading
* Useful for updating CDN tokens
* @param {string | object} urlOrManifest
*/
function updateSource(urlOrManifest) {
source = urlOrManifest
streamController.load(source);
}
/**
* Use this method to set a source URL to a valid MPD manifest file OR
* a previously downloaded and parsed manifest object. Optionally, can
* also provide protection information
*
* @param {string|Object} urlOrManifest - A URL to a valid MPD manifest file, or a
* parsed manifest object.
* @param {number|string} startTime - For VoD content the start time is relative to the start time of the first period.
* For live content
* If the parameter starts from prefix posix: it signifies the absolute time range defined in seconds of Coordinated Universal Time (ITU-R TF.460-6). This is the number of seconds since 01-01-1970 00:00:00 UTC. Fractions of seconds may be optionally specified down to the millisecond level.
* If no posix prefix is used the starttime is relative to MPD@availabilityStartTime
*
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
*
* @memberof module:MediaPlayer
* @instance
*/
function attachSource(urlOrManifest, startTime = NaN) {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
if (typeof urlOrManifest === 'string') {
uriFragmentModel.initialize(urlOrManifest);
}
Iif (startTime == null) {
startTime = NaN;
}
Iif (!isNaN(startTime)) {
startTime = Math.max(0, startTime);
}
providedStartTime = startTime;
source = urlOrManifest;
Iif (streamingInitialized || playbackInitialized) {
_resetPlaybackControllers();
_resetPlaybackSessionSpecificSettings()
}
if (isReady()) {
_initializePlayback(providedStartTime);
}
}
/**
* Reload the manifest that the player is currently using.
*
* @memberof module:MediaPlayer
* @param {function} callback - A Callback function provided when retrieving manifests
* @instance
*/
function refreshManifest(callback) {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
if (!isReady()) {
return callback(null, SOURCE_NOT_ATTACHED_ERROR);
}
let self = this;
if (typeof callback === 'function') {
const handler = function (e) {
eventBus.off(Events.INTERNAL_MANIFEST_LOADED, handler, self);
if (e.error) {
callback(null, e.error);
return;
}
callback(e.manifest);
};
eventBus.on(Events.INTERNAL_MANIFEST_LOADED, handler, self);
}
streamController.refreshManifest();
}
/**
* Get the current settings object being used on the player.
* @returns {PlayerSettings} The settings object being used.
*
* @memberof module:MediaPlayer
* @instance
*/
function getSettings() {
return settings.get();
}
/**
* @summary Update the current settings object being used on the player. Anything left unspecified is not modified.
* @param {PlayerSettings} settingsObj - An object corresponding to the settings definition.
* @description This function does not update the entire object, only properties in the passed in object are updated.
*
* This means that updateSettings({a: x}) and updateSettings({b: y}) are functionally equivalent to
* updateSettings({a: x, b: y}). If the default values are required again, @see{@link resetSettings}.
* @example
* player.updateSettings({
* streaming: {
* lowLatencyEnabled: false,
* abr: {
* maxBitrate: { audio: 100, video: 1000 }
* }
* }
* });
* @memberof module:MediaPlayer
* @instance
*/
function updateSettings(settingsObj) {
settings.update(settingsObj);
}
/**
* Resets the settings object back to the default.
*
* @memberof module:MediaPlayer
* @instance
*/
function resetSettings() {
settings.reset();
}
/**
* A utility methods which converts UTC timestamp value into a valid time and date string.
*
* @param {number} time - UTC timestamp to be converted into date and time.
* @param {string} locales - a region identifier (i.e. en_US).
* @param {boolean} hour12 - 12 vs 24 hour. Set to true for 12 hour time formatting.
* @param {boolean} withDate - default is false. Set to true to append current date to UTC time format.
* @returns {string} A formatted time and date string.
* @memberof module:MediaPlayer
* @instance
*/
function formatUTC(time, locales, hour12, withDate = false) {
const dt = new Date(time * 1000);
const d = dt.toLocaleDateString(locales);
const t = dt.toLocaleTimeString(locales, {
hour12: hour12
});
return withDate ? t + ' ' + d : t;
}
/**
* A utility method which converts seconds into TimeCode (i.e. 300 --> 05:00).
*
* @param {number} value - A number in seconds to be converted into a formatted time code.
* @returns {string} A formatted time code string.
* @memberof module:MediaPlayer
* @instance
*/
function convertToTimeCode(value) {
value = Math.max(value, 0);
let h = Math.floor(value / 3600);
let m = Math.floor((value % 3600) / 60);
let s = Math.floor((value % 3600) % 60);
return (h === 0 ? '' : (h < 10 ? '0' + h.toString() + ':' : h.toString() + ':')) + (m < 10 ? '0' + m.toString() : m.toString()) + ':' + (s < 10 ? '0' + s.toString() : s.toString());
}
/**
* This method should be used to extend or replace internal dash.js objects.
* There are two ways to extend dash.js (determined by the override argument):
* <ol>
* <li>If you set override to true any public method or property in your custom object will
* override the dash.js parent object's property(ies) and will be used instead but the
* dash.js parent module will still be created.</li>
*
* <li>If you set override to false your object will completely replace the dash.js object.
* (Note: This is how it was in 1.x of Dash.js with Dijon).</li>
* </ol>
* <b>When you extend you get access to this.context, this.factory and this.parent to operate with in your custom object.</b>
* <ul>
* <li><b>this.context</b> - can be used to pass context for singleton access.</li>
* <li><b>this.factory</b> - can be used to call factory.getSingletonInstance().</li>
* <li><b>this.parent</b> - is the reference of the parent object to call other public methods. (this.parent is excluded if you extend with override set to false or option 2)</li>
* </ul>
* <b>You must call extend before you call initialize</b>
* @see {@link module:MediaPlayer#initialize initialize()}
* @param {string} parentNameString - name of parent module
* @param {Object} childInstance - overriding object
* @param {boolean} override - replace only some methods (true) or the whole object (false)
* @memberof module:MediaPlayer
* @instance
*/
function extend(parentNameString, childInstance, override) {
FactoryMaker.extend(parentNameString, childInstance, override, context);
}
/**
* This method returns the active stream
*
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function getActiveStream() {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
let streamInfo = streamController.getActiveStreamInfo();
return streamInfo ? streamController.getStreamById(streamInfo.id) : null;
}
/**
* Returns the DashAdapter.js Module.
*
* @see {@link module:DashAdapter}
* @returns {Object}
* @memberof module:MediaPlayer
* @instance
*/
function getDashAdapter() {
return adapter;
}
/**
* Triggers a request to the content steering server to update the steering information.
* @return {Promise<any>}
*/
function triggerSteeringRequest() {
if (contentSteeringController) {
return contentSteeringController.loadSteeringData();
}
}
/**
* Returns the current response data of the content steering server
* @return {object}
*/
function getCurrentSteeringResponseData() {
if (contentSteeringController) {
return contentSteeringController.getCurrentSteeringResponseData();
}
}
/**
* Returns the current manifest
* @returns {object}
*/
function getManifest() {
return manifestModel.getValue();
}
/**
* Returns all BaseURLs that are available including synthesized elements (e.g by content steering)
* @returns {BaseURL[]}
*/
function getAvailableBaseUrls() {
const manifest = manifestModel.getValue();
if (!manifest) {
return [];
}
return baseURLController.getBaseUrls(manifest);
}
/**
* Returns the available location elements including synthesized elements (e.g by content steering)
* @returns {MpdLocation[]}
*/
function getAvailableLocations() {
const manifest = manifestModel.getValue();
if (!manifest) {
return [];
}
const manifestLocations = adapter.getLocation(manifest);
const synthesizedElements = contentSteeringController.getSynthesizedLocationElements(manifestLocations);
return manifestLocations.concat(synthesizedElements);
}
//***********************************
// PRIVATE METHODS
//***********************************
function _resetPlaybackControllers() {
playbackInitialized = false;
streamingInitialized = false;
adapter.reset();
streamController.reset();
gapController.reset();
catchupController.reset();
playbackController.reset();
serviceDescriptionController.reset();
contentSteeringController.reset();
abrController.reset();
throughputController.reset();
mediaController.reset();
segmentBaseController.reset();
Iif (protectionController) {
if (settings.get().streaming.protection.keepProtectionMediaKeys) {
protectionController.stop();
} else {
protectionController.reset();
protectionController = null;
_detectProtection();
}
}
textController.reset();
cmcdModel.reset();
cmsdModel.reset();
}
function _resetPlaybackSessionSpecificSettings() {
customParametersModel.resetPlaybackSessionSpecificSettings()
}
function _createPlaybackControllers() {
// creates or get objects instances
const manifestLoader = _createManifestLoader();
Iif (!streamController) {
streamController = StreamController(context).getInstance();
}
if (!textController) {
textController = TextController(context).create({
errHandler,
manifestModel,
adapter,
mediaController,
baseURLController,
videoModel,
settings
});
}
capabilitiesFilter.setConfig({
capabilities,
customParametersModel,
adapter,
settings,
protectionController,
manifestModel,
errHandler
});
streamController.setConfig({
capabilities,
capabilitiesFilter,
manifestLoader,
manifestModel,
mediaPlayerModel,
customParametersModel,
protectionController,
textController,
adapter,
dashMetrics,
errHandler,
timelineConverter,
videoModel,
playbackController,
serviceDescriptionController,
contentSteeringController,
abrController,
throughputController,
mediaController,
settings,
baseURLController,
uriFragmentModel,
segmentBaseController
});
gapController.setConfig({
settings,
playbackController,
streamController,
videoModel,
timelineConverter,
adapter
});
playbackController.setConfig({
streamController,
serviceDescriptionController,
dashMetrics,
adapter,
videoModel,
timelineConverter,
settings
});
catchupController.setConfig({
streamController,
playbackController,
mediaPlayerModel,
videoModel,
settings
})
throughputController.setConfig({
settings,
playbackController
})
abrController.setConfig({
streamController,
capabilities,
domStorage,
mediaPlayerModel,
customParametersModel,
throughputController,
cmsdModel,
dashMetrics,
adapter,
videoModel,
settings
});
cmcdModel.setConfig({
abrController,
dashMetrics,
playbackController,
serviceDescriptionController,
throughputController,
});
clientDataReportingController.setConfig({
serviceDescriptionController
})
cmsdModel.setConfig({});
// initializes controller
mediaController.initialize();
throughputController.initialize();
abrController.initialize();
streamController.initialize(autoPlay, protectionData);
textController.initialize();
gapController.initialize();
catchupController.initialize();
cmcdModel.initialize(autoPlay);
cmsdModel.initialize();
contentSteeringController.initialize();
segmentBaseController.initialize();
}
function _createManifestLoader() {
return ManifestLoader(context).create({
debug: debug,
errHandler: errHandler,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
mssHandler: mssHandler,
settings: settings
});
}
function _detectProtection() {
Iif (protectionController) {
return protectionController;
}
Iif (typeof dashjs === 'undefined') {
return null
}
// do not require Protection as dependencies as this is optional and intended to be loaded separately
let detectedProtection = dashjs.Protection;
if (typeof detectedProtection === 'function') { //TODO need a better way to register/detect plugin components
let protection = detectedProtection(context).create();
Events.extend(detectedProtection.events);
MediaPlayerEvents.extend(detectedProtection.events, {
publicOnly: true
});
Errors.extend(detectedProtection.errors);
protectionController = protection.createProtectionSystem({
debug,
errHandler,
videoModel,
customParametersModel,
capabilities,
eventBus,
events: Events,
BASE64,
constants: Constants,
cmcdModel,
settings
});
Iif (!capabilities) {
capabilities = Capabilities(context).getInstance();
}
capabilities.setProtectionController(protectionController);
return protectionController;
}
return null;
}
function _detectMetricsReporting() {
if (metricsReportingController || typeof dashjs === 'undefined') {
return;
}
// do not require MetricsReporting as dependencies as this is optional and intended to be loaded separately
let detectedMetricsReporting = dashjs.MetricsReporting;
if (typeof detectedMetricsReporting === 'function') { //TODO need a better way to register/detect plugin components
let metricsReporting = detectedMetricsReporting(context).create();
metricsReportingController = metricsReporting.createMetricsReporting({
debug: debug,
eventBus: eventBus,
mediaElement: getVideoElement(),
adapter: adapter,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
events: Events,
constants: Constants,
metricsConstants: MetricsConstants
});
}
}
function _detectMss() {
Iif (mssHandler || typeof dashjs === 'undefined') {
return;
}
// do not require MssHandler as dependencies as this is optional and intended to be loaded separately
let detectedMssHandler = dashjs.MssHandler;
Iif (typeof detectedMssHandler === 'function') { //TODO need a better way to register/detect plugin components
Errors.extend(detectedMssHandler.errors);
mssHandler = detectedMssHandler(context).create({
eventBus: eventBus,
mediaPlayerModel: mediaPlayerModel,
dashMetrics: dashMetrics,
manifestModel: manifestModel,
playbackController: playbackController,
streamController: streamController,
protectionController: protectionController,
baseURLController: baseURLController,
errHandler: errHandler,
events: Events,
constants: Constants,
debug: debug,
initSegmentType: HTTPRequest.INIT_SEGMENT_TYPE,
BASE64: BASE64,
ISOBoxer: ISOBoxer,
settings: settings
});
}
}
function _detectOffline() {
Iif (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
Iif (offlineController) {
return offlineController;
}
Iif (typeof dashjs === 'undefined') {
return null
}
// do not require Offline as dependencies as this is optional and intended to be loaded separately
let detectedOfflineController = dashjs.OfflineController;
Iif (typeof detectedOfflineController === 'function') { //TODO need a better way to register/detect plugin components
Events.extend(detectedOfflineController.events);
MediaPlayerEvents.extend(detectedOfflineController.events, {
publicOnly: true
});
Errors.extend(detectedOfflineController.errors);
const manifestLoader = _createManifestLoader();
const manifestUpdater = ManifestUpdater(context).create();
manifestUpdater.setConfig({
manifestModel,
adapter,
manifestLoader,
errHandler,
contentSteeringController
});
offlineController = detectedOfflineController(context).create({
debug: debug,
manifestUpdater: manifestUpdater,
baseURLController: baseURLController,
manifestLoader: manifestLoader,
manifestModel: manifestModel,
mediaPlayerModel: mediaPlayerModel,
abrController: abrController,
playbackController: playbackController,
adapter: adapter,
errHandler: errHandler,
dashMetrics: dashMetrics,
timelineConverter: timelineConverter,
segmentBaseController: segmentBaseController,
schemeLoaderFactory: schemeLoaderFactory,
eventBus: eventBus,
events: Events,
errors: Errors,
constants: Constants,
settings: settings,
dashConstants: DashConstants,
urlUtils: URLUtils(context).getInstance()
});
return offlineController;
}
return null;
}
function _sanitizeSettings(value) {
const defaults = settings.get().streaming.defaultSchemeIdUri;
let output = {};
function __sanitizeDescriptorType(name, val, defaultSchemeIdUri) {
let out = {};
// For an empty string, let's unset the descriptor, i.e. return null
if (val) {
Iif (val instanceof Array) {
throw ARRAY_NOT_SUPPORTED_ERROR;
} else if (val instanceof Object) {
out.schemeIdUri = val.schemeIdUri ? val.schemeIdUri : '';
out.value = val.value ? val.value : '';
} else {
out.schemeIdUri = defaultSchemeIdUri;
out.value = val;
logger.warn('No schemeIdUri provided for ' + name + ', using default \"' + defaultSchemeIdUri + '\"');
}
return out;
}
return null;
}
Iif (value.id !== undefined) {
output.id = value.id;
}
if (value.lang !== undefined) {
output.lang = value.lang;
}
Iif (!isNaN(value.index)) {
output.index = value.index;
}
if (value.viewpoint !== undefined) {
output.viewpoint = __sanitizeDescriptorType('viewpoint', value.viewpoint, defaults.viewpoint);
}
if (value.audioChannelConfiguration !== undefined) {
output.audioChannelConfiguration = __sanitizeDescriptorType('audioChannelConfiguration', value.audioChannelConfiguration, defaults.audioChannelConfiguration);
}
if (value.role !== undefined && value.role !== null) {
output.role = __sanitizeDescriptorType('role', value.role, defaults.role);
// conceal misspelled "Main" from earlier MPEG-DASH editions (fixed with 6th edition)
Iif (output.role.schemeIdUri === Constants.DASH_ROLE_SCHEME_ID && output.role.value === 'Main') {
output.role.value = DashConstants.MAIN;
}
}
if (value.accessibility !== undefined) {
output.accessibility = __sanitizeDescriptorType('accessibility', value.accessibility, defaults.accessibility);
}
return output;
}
/**
*
* @private
*/
function _initializePlayback(startTime = NaN) {
Iif (offlineController) {
offlineController.resetRecords();
}
if (!streamingInitialized && source) {
streamingInitialized = true;
logger.info('Streaming Initialized');
_createPlaybackControllers();
if (typeof source === 'string') {
streamController.load(source, startTime);
} else E{
streamController.loadWithManifest(source, startTime);
}
}
if (!playbackInitialized && isReady()) {
playbackInitialized = true;
eventBus.trigger(MediaPlayerEvents.PLAYBACK_INITIALIZED)
logger.info('Playback Initialized');
}
}
instance = {
addABRCustomRule,
addExternalSubtitle,
addRequestInterceptor,
addResponseInterceptor,
addUTCTimingSource,
attachProtectionController,
attachSource,
attachTTMLRenderingDiv,
attachView,
attachVttRenderingDiv,
clearDefaultUTCTimingSources,
convertToTimeCode,
destroy,
duration,
enableForcedTextStreaming,
enableText,
extend,
formatUTC,
getABRCustomRules,
getActiveStream,
getAutoPlay,
getAvailableBaseUrls,
getAvailableLocations,
getAverageLatency,
getAverageThroughput,
getBufferLength,
getCurrentLiveLatency,
getCurrentRepresentationForType,
getCurrentSteeringResponseData,
getCurrentTextTrackIndex,
getCurrentTrackFor,
getDashAdapter,
getDashMetrics,
getDebug,
getDvrSeekOffset,
getDvrWindow,
getExternalSubtitles,
getInitialMediaSettingsFor,
getLowLatencyModeEnabled,
getManifest,
getOfflineController,
getPlaybackRate,
getProtectionController,
getRawThroughputData,
getRepresentationsByType,
getSafeAverageThroughput,
getSettings,
getSource,
getStreamsFromManifest,
getTTMLRenderingDiv,
getTargetLiveDelay,
getTracksFor,
getTracksForTypeFromManifest,
getVersion,
getVideoElement,
getVolume,
getXHRWithCredentialsForType,
initialize,
isDynamic,
isMuted,
isPaused,
isReady,
isSeeking,
isTextEnabled,
off,
on,
pause,
play,
preload,
provideThumbnail,
refreshManifest,
registerCustomCapabilitiesFilter,
registerLicenseRequestFilter,
registerLicenseResponseFilter,
removeABRCustomRule,
removeAllABRCustomRule,
removeExternalSubtitleById,
removeExternalSubtitleByUrl,
removeRequestInterceptor,
removeResponseInterceptor,
removeUTCTimingSource,
reset,
resetCustomInitialTrackSelectionFunction,
resetSettings,
restoreDefaultUTCTimingSources,
retrieveManifest,
seek,
seekToOriginalLive,
seekToPresentationTime,
setAutoPlay,
setConfig,
setCurrentTrack,
setCustomInitialTrackSelectionFunction,
setInitialMediaSettingsFor,
setMute,
setPlaybackRate,
setProtectionData,
setRepresentationForTypeById,
setRepresentationForTypeByIndex,
setTextTrack,
setVolume,
setXHRWithCredentialsForType,
time,
timeAsUTC,
timeInDvrWindow,
trigger,
triggerSteeringRequest,
unregisterCustomCapabilitiesFilter,
unregisterLicenseRequestFilter,
unregisterLicenseResponseFilter,
updateSettings,
updateSource,
};
setup();
return instance;
}
MediaPlayer.__dashjs_factory_name = 'MediaPlayer';
const factory = FactoryMaker.getClassFactory(MediaPlayer);
factory.events = MediaPlayerEvents;
factory.errors = Errors;
FactoryMaker.updateClassFactory(MediaPlayer.__dashjs_factory_name, factory);
export default factory;
|