MediaCategoryViewController.swift 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*****************************************************************************
  2. * MediaCateogoryViewController.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <nitz.carola # gmail.com>
  9. * Mike JS. Choi <mkchoi212 # icloud.com>
  10. *
  11. * Refer to the COPYING file of the official project for license.
  12. *****************************************************************************/
  13. import Foundation
  14. protocol MediaCategoryViewControllerDelegate: NSObjectProtocol {
  15. func needsToUpdateNavigationbarIfNeeded(_ viewController: MediaCategoryViewController)
  16. func enableCategorySwitching(for viewController: MediaCategoryViewController,
  17. enable: Bool)
  18. }
  19. class MediaCategoryViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchBarDelegate, IndicatorInfoProvider {
  20. var model: MediaLibraryBaseModel
  21. private var services: Services
  22. var searchBar = UISearchBar(frame: .zero)
  23. var isSearching: Bool = false
  24. private var searchBarConstraint: NSLayoutConstraint?
  25. private let searchDataSource: LibrarySearchDataSource
  26. private let searchBarSize: CGFloat = 50.0
  27. private var rendererButton: UIButton
  28. private lazy var editController: EditController = {
  29. let editController = EditController(mediaLibraryService:services.medialibraryService, model: model)
  30. editController.delegate = self
  31. return editController
  32. }()
  33. private var editToolbarConstraint: NSLayoutConstraint?
  34. private var cachedCellSize = CGSize.zero
  35. private var toSize = CGSize.zero
  36. private var longPressGesture: UILongPressGestureRecognizer!
  37. weak var delegate: MediaCategoryViewControllerDelegate?
  38. // @available(iOS 11.0, *)
  39. // lazy var dragAndDropManager: VLCDragAndDropManager = { () -> VLCDragAndDropManager<T> in
  40. // VLCDragAndDropManager<T>(subcategory: VLCMediaSubcategories<>)
  41. // }()
  42. @objc private lazy var sortActionSheet: ActionSheet = {
  43. let header = ActionSheetSortSectionHeader(model: model.sortModel)
  44. let actionSheet = ActionSheet(header: header)
  45. header.delegate = self
  46. actionSheet.delegate = self
  47. actionSheet.dataSource = self
  48. actionSheet.modalPresentationStyle = .custom
  49. actionSheet.setAction { [weak self] item in
  50. guard let sortingCriteria = item as? VLCMLSortingCriteria else {
  51. return
  52. }
  53. self?.model.sort(by: sortingCriteria, desc: header.actionSwitch.isOn)
  54. self?.sortActionSheet.removeActionSheet()
  55. }
  56. return actionSheet
  57. }()
  58. lazy var emptyView: VLCEmptyLibraryView = {
  59. let name = String(describing: VLCEmptyLibraryView.self)
  60. let nib = Bundle.main.loadNibNamed(name, owner: self, options: nil)
  61. guard let emptyView = nib?.first as? VLCEmptyLibraryView else { fatalError("Can't find nib for \(name)") }
  62. return emptyView
  63. }()
  64. let editCollectionViewLayout: UICollectionViewFlowLayout = {
  65. let editCollectionViewLayout = UICollectionViewFlowLayout()
  66. editCollectionViewLayout.minimumLineSpacing = 1
  67. editCollectionViewLayout.minimumInteritemSpacing = 0
  68. return editCollectionViewLayout
  69. }()
  70. @available(*, unavailable)
  71. init() {
  72. fatalError()
  73. }
  74. init(services: Services, model: MediaLibraryBaseModel) {
  75. self.services = services
  76. self.model = model
  77. self.rendererButton = services.rendererDiscovererManager.setupRendererButton()
  78. self.searchDataSource = LibrarySearchDataSource(model: model)
  79. super.init(collectionViewLayout: UICollectionViewFlowLayout())
  80. if let collection = model as? CollectionModel {
  81. title = collection.mediaCollection.title()
  82. }
  83. NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
  84. navigationItem.rightBarButtonItems = [editButtonItem, UIBarButtonItem(customView: rendererButton)]
  85. }
  86. func setupSearchBar() {
  87. searchBar.delegate = self
  88. searchBar.searchBarStyle = .minimal
  89. searchBar.translatesAutoresizingMaskIntoConstraints = false
  90. searchBar.placeholder = NSLocalizedString("SEARCH", comment: "")
  91. searchBar.backgroundColor = PresentationTheme.current.colors.background
  92. if #available(iOS 11.0, *) {
  93. navigationItem.largeTitleDisplayMode = .never
  94. }
  95. if let textfield = searchBar.value(forKey: "searchField") as? UITextField {
  96. if let backgroundview = textfield.subviews.first {
  97. backgroundview.backgroundColor = UIColor.white
  98. backgroundview.layer.cornerRadius = 10
  99. backgroundview.clipsToBounds = true
  100. }
  101. }
  102. searchBarConstraint = searchBar.topAnchor.constraint(equalTo: view.topAnchor, constant: -searchBarSize)
  103. view.addSubview(searchBar)
  104. NSLayoutConstraint.activate([
  105. searchBarConstraint!,
  106. searchBar.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10),
  107. searchBar.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -10),
  108. searchBar.heightAnchor.constraint(equalToConstant: searchBarSize)
  109. ])
  110. }
  111. override var preferredStatusBarStyle: UIStatusBarStyle {
  112. return PresentationTheme.current.colors.statusBarStyle
  113. }
  114. @objc func reloadData() {
  115. DispatchQueue.main.async {
  116. [weak self] in
  117. guard let self = self else {
  118. return
  119. }
  120. self.delegate?.needsToUpdateNavigationbarIfNeeded(self)
  121. self.collectionView?.reloadData()
  122. self.updateUIForContent()
  123. }
  124. }
  125. @available(*, unavailable)
  126. required init?(coder aDecoder: NSCoder) {
  127. fatalError("init(coder: ) has not been implemented")
  128. }
  129. override func viewDidLoad() {
  130. super.viewDidLoad()
  131. setupCollectionView()
  132. setupSearchBar()
  133. setupEditToolbar()
  134. _ = (MLMediaLibrary.sharedMediaLibrary() as! MLMediaLibrary).libraryDidAppear()
  135. }
  136. override func viewWillAppear(_ animated: Bool) {
  137. super.viewWillAppear(animated)
  138. let manager = services.rendererDiscovererManager
  139. if manager.discoverers.isEmpty {
  140. // Either didn't start or stopped before
  141. manager.start()
  142. }
  143. manager.presentingViewController = self
  144. cachedCellSize = .zero
  145. collectionView.collectionViewLayout.invalidateLayout()
  146. }
  147. @objc func themeDidChange() {
  148. collectionView?.backgroundColor = PresentationTheme.current.colors.background
  149. searchBar.backgroundColor = PresentationTheme.current.colors.background
  150. editController.view.backgroundColor = PresentationTheme.current.colors.background
  151. setNeedsStatusBarAppearanceUpdate()
  152. }
  153. func setupEditToolbar() {
  154. editController.view.translatesAutoresizingMaskIntoConstraints = false
  155. view.addSubview(editController.view)
  156. var guide: LayoutAnchorContainer = view
  157. if #available(iOS 11.0, *) {
  158. guide = view.safeAreaLayoutGuide
  159. }
  160. editToolbarConstraint = editController.view.bottomAnchor.constraint(equalTo: guide.bottomAnchor, constant: EditToolbar.height)
  161. NSLayoutConstraint.activate([
  162. editToolbarConstraint!,
  163. editController.view.leadingAnchor.constraint(equalTo: guide.leadingAnchor),
  164. editController.view.trailingAnchor.constraint(equalTo: guide.trailingAnchor),
  165. editController.view.heightAnchor.constraint(equalToConstant: 50)
  166. ])
  167. }
  168. override func viewDidAppear(_ animated: Bool) {
  169. super.viewDidAppear(animated)
  170. reloadData()
  171. }
  172. func isEmptyCollectionView() -> Bool {
  173. return collectionView?.numberOfItems(inSection: 0) == 0
  174. }
  175. func updateUIForContent() {
  176. if isSearching {
  177. return
  178. }
  179. let isEmpty = isEmptyCollectionView()
  180. if isEmpty {
  181. collectionView?.setContentOffset(.zero, animated: false)
  182. }
  183. searchBar.isHidden = isEmpty || isEditing
  184. collectionView?.backgroundView = isEmpty ? emptyView : nil
  185. }
  186. // MARK: Renderer
  187. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  188. super.viewWillTransition(to: size, with: coordinator)
  189. cachedCellSize = .zero
  190. toSize = size
  191. collectionView?.collectionViewLayout.invalidateLayout()
  192. }
  193. // MARK: - Edit
  194. override func scrollViewDidScroll(_ scrollView: UIScrollView) {
  195. // This ensures that the search bar is always visible like a sticky while searching
  196. if isSearching {
  197. searchBar.endEditing(true)
  198. delegate?.enableCategorySwitching(for: self, enable: true)
  199. // End search if scrolled and the textfield is empty
  200. if let searchBarText = searchBar.text, searchBarText.isEmpty {
  201. searchBarCancelButtonClicked(searchBar)
  202. }
  203. return
  204. }
  205. searchBarConstraint?.constant = -min(scrollView.contentOffset.y, searchBarSize) - searchBarSize
  206. if scrollView.contentOffset.y < -searchBarSize && scrollView.contentInset.top != searchBarSize {
  207. collectionView.contentInset = UIEdgeInsets(top: searchBarSize, left: 0, bottom: 0, right: 0)
  208. }
  209. if scrollView.contentOffset.y >= 0 && scrollView.contentInset.top != 0 {
  210. collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  211. }
  212. }
  213. override func setEditing(_ editing: Bool, animated: Bool) {
  214. super.setEditing(editing, animated: animated)
  215. // might have an issue if the old datasource was search
  216. // Most of the edit logic is handled inside editController
  217. collectionView?.dataSource = editing ? editController : self
  218. collectionView?.delegate = editing ? editController : self
  219. editController.resetSelections()
  220. displayEditToolbar()
  221. let layoutToBe = editing ? editCollectionViewLayout : UICollectionViewFlowLayout()
  222. collectionView?.setCollectionViewLayout(layoutToBe, animated: false, completion: {
  223. [unowned self] finished in
  224. guard finished else {
  225. assertionFailure("VLCMediaSubcategoryViewController: Edit layout transition failed.")
  226. return
  227. }
  228. self.searchBarConstraint?.constant = -self.searchBarSize
  229. self.reloadData()
  230. })
  231. }
  232. private func displayEditToolbar() {
  233. UIView.animate(withDuration: 0.3) { [weak self] in
  234. self?.editToolbarConstraint?.constant = self?.isEditing == true ? 0 : EditToolbar.height
  235. self?.view.layoutIfNeeded()
  236. self?.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: self?.isEditing == true ? EditToolbar.height : 0, right: 0)
  237. }
  238. }
  239. func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
  240. let uiTestAccessibilityIdentifier = model is TrackModel ? VLCAccessibilityIdentifier.songs : nil
  241. return IndicatorInfo(title: model.indicatorName, accessibilityIdentifier: uiTestAccessibilityIdentifier)
  242. }
  243. // MARK: - UICollectionViewDataSource
  244. override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  245. return isSearching ? searchDataSource.searchData.count : model.anyfiles.count
  246. }
  247. override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  248. guard let mediaCell = collectionView.dequeueReusableCell(withReuseIdentifier:model.cellType.defaultReuseIdentifier, for: indexPath) as? BaseCollectionViewCell else {
  249. assertionFailure("you forgot to register the cell or the cell is not a subclass of BaseCollectionViewCell")
  250. return UICollectionViewCell()
  251. }
  252. let mediaObject = isSearching ? searchDataSource.objectAtIndex(index: indexPath.row) : model.anyfiles[indexPath.row]
  253. if let media = mediaObject as? VLCMLMedia {
  254. // FIXME: This should be done in the VModel, workaround for the release.
  255. if media.type() == .video {
  256. services.medialibraryService.requestThumbnail(for: media)
  257. }
  258. assert(media.mainFile() != nil, "The mainfile is nil")
  259. mediaCell.media = media.mainFile() != nil ? media : nil
  260. } else {
  261. mediaCell.media = mediaObject
  262. }
  263. mediaCell.isAccessibilityElement = true
  264. return mediaCell
  265. }
  266. // MARK: - UICollectionViewDelegate
  267. override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  268. let modelContent = isSearching ? searchDataSource.objectAtIndex(index: indexPath.row) : model.anyfiles[indexPath.row]
  269. if let media = modelContent as? VLCMLMedia {
  270. play(media: media, at: indexPath)
  271. createSpotlightItem(media: media)
  272. } else if let mediaCollection = modelContent as? MediaCollectionModel {
  273. let collectionViewController = CollectionCategoryViewController(services, mediaCollection: mediaCollection)
  274. navigationController?.pushViewController(collectionViewController, animated: true)
  275. }
  276. }
  277. func createSpotlightItem(media: VLCMLMedia) {
  278. if KeychainCoordinator.passcodeLockEnabled {
  279. return
  280. }
  281. userActivity = NSUserActivity(activityType: kVLCUserActivityPlaying)
  282. userActivity?.title = media.title
  283. userActivity?.contentAttributeSet = media.coreSpotlightAttributeSet()
  284. userActivity?.userInfo = ["playingmedia" : media.identifier()]
  285. userActivity?.isEligibleForSearch = true
  286. userActivity?.isEligibleForHandoff = true
  287. userActivity?.becomeCurrent()
  288. }
  289. }
  290. // MARK: - UISearchBarDelegate
  291. extension MediaCategoryViewController {
  292. func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
  293. reloadData()
  294. isSearching = true
  295. delegate?.enableCategorySwitching(for: self, enable: false)
  296. searchBar.setShowsCancelButton(true, animated: true)
  297. }
  298. func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
  299. searchBar.resignFirstResponder()
  300. // Empty the text field and reset the research
  301. searchBar.text = ""
  302. searchDataSource.shouldReloadFor(searchString: "")
  303. searchBar.setShowsCancelButton(false, animated: true)
  304. isSearching = false
  305. delegate?.enableCategorySwitching(for: self, enable: true)
  306. reloadData()
  307. }
  308. func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
  309. searchBar.resignFirstResponder()
  310. delegate?.enableCategorySwitching(for: self, enable: true)
  311. }
  312. func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
  313. searchDataSource.shouldReloadFor(searchString: searchText)
  314. reloadData()
  315. if searchText.isEmpty {
  316. self.searchBar.resignFirstResponder
  317. }
  318. }
  319. }
  320. // MARK: - UICollectionViewDelegateFlowLayout
  321. extension MediaCategoryViewController {
  322. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  323. if cachedCellSize == .zero {
  324. //For iOS 10 when rotating we take the value from willTransition to size, for the first layout pass that value is 0 though,
  325. //so we need the frame.size width. For rotation on iOS 11 this approach doesn't work because at the time when this is called
  326. //we don't have yet the updated safeare layout frame. This is addressed by relayouting from viewSafeAreaInsetsDidChange
  327. var toWidth = toSize.width != 0 ? toSize.width : collectionView.frame.size.width
  328. if #available(iOS 11.0, *) {
  329. toWidth = collectionView.safeAreaLayoutGuide.layoutFrame.width
  330. }
  331. cachedCellSize = model.cellType.cellSizeForWidth(toWidth)
  332. }
  333. return cachedCellSize
  334. }
  335. override func viewSafeAreaInsetsDidChange() {
  336. cachedCellSize = .zero
  337. collectionView?.collectionViewLayout.invalidateLayout()
  338. }
  339. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  340. return UIEdgeInsets(top: model.cellType.edgePadding, left: model.cellType.edgePadding, bottom: model.cellType.edgePadding, right: model.cellType.edgePadding)
  341. }
  342. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  343. return model.cellType.edgePadding
  344. }
  345. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  346. return model.cellType.interItemPadding
  347. }
  348. func handleSort() {
  349. var currentSortIndex: Int = 0
  350. for (index, criteria) in
  351. model.sortModel.sortingCriteria.enumerated()
  352. where criteria == model.sortModel.currentSort {
  353. currentSortIndex = index
  354. break
  355. }
  356. present(sortActionSheet, animated: false) {
  357. [sortActionSheet, currentSortIndex] in
  358. sortActionSheet.collectionView.selectItem(at:
  359. IndexPath(row: currentSortIndex, section: 0), animated: false,
  360. scrollPosition: .centeredVertically)
  361. }
  362. }
  363. func handleSortShortcut() {
  364. model.sort(by: model.sortModel.currentSort, desc: !model.sortModel.desc)
  365. }
  366. }
  367. // MARK: VLCActionSheetDelegate
  368. extension MediaCategoryViewController: ActionSheetDelegate {
  369. func headerViewTitle() -> String? {
  370. return NSLocalizedString("HEADER_TITLE_SORT", comment: "")
  371. }
  372. // This provide the item to send to the selection action
  373. func itemAtIndexPath(_ indexPath: IndexPath) -> Any? {
  374. let enabledSortCriteria = model.sortModel.sortingCriteria
  375. if indexPath.row < enabledSortCriteria.count {
  376. return enabledSortCriteria[indexPath.row]
  377. }
  378. assertionFailure("VLCMediaCategoryViewController: VLCActionSheetDelegate: IndexPath out of range")
  379. return nil
  380. }
  381. }
  382. // MARK: VLCActionSheetDataSource
  383. extension MediaCategoryViewController: ActionSheetDataSource {
  384. func numberOfRows() -> Int {
  385. return model.sortModel.sortingCriteria.count
  386. }
  387. func actionSheet(collectionView: UICollectionView,
  388. cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  389. guard let cell = collectionView.dequeueReusableCell(
  390. withReuseIdentifier: ActionSheetCell.identifier,
  391. for: indexPath) as? ActionSheetCell else {
  392. assertionFailure("VLCMediaCategoryViewController: VLCActionSheetDataSource: Unable to dequeue reusable cell")
  393. return UICollectionViewCell()
  394. }
  395. let sortingCriterias = model.sortModel.sortingCriteria
  396. guard indexPath.row < sortingCriterias.count else {
  397. assertionFailure("VLCMediaCategoryViewController: VLCActionSheetDataSource: IndexPath out of range")
  398. return cell
  399. }
  400. cell.name.text = String(describing: sortingCriterias[indexPath.row])
  401. return cell
  402. }
  403. }
  404. // MARK: - ActionSheetSortSectionHeaderDelegate
  405. extension MediaCategoryViewController: ActionSheetSortSectionHeaderDelegate {
  406. func actionSheetSortSectionHeader(_ header: ActionSheetSortSectionHeader,
  407. onSwitchIsOnChange: Bool) {
  408. model.sort(by: model.sortModel.currentSort, desc: onSwitchIsOnChange)
  409. }
  410. }
  411. // MARK: - EditControllerDelegate
  412. extension MediaCategoryViewController: EditControllerDelegate {
  413. func editController(editController: EditController, cellforItemAt indexPath: IndexPath) -> MediaEditCell? {
  414. return collectionView.cellForItem(at: indexPath) as? MediaEditCell
  415. }
  416. func editController(editController: EditController,
  417. present viewController: UIViewController) {
  418. let newNavigationController = UINavigationController(rootViewController: viewController)
  419. navigationController?.present(newNavigationController, animated: true, completion: nil)
  420. }
  421. }
  422. private extension MediaCategoryViewController {
  423. func setupCollectionView() {
  424. let cellNib = UINib(nibName: model.cellType.nibName, bundle: nil)
  425. collectionView?.register(cellNib, forCellWithReuseIdentifier: model.cellType.defaultReuseIdentifier)
  426. if let editCell = (model as? EditableMLModel)?.editCellType() {
  427. let editCellNib = UINib(nibName: editCell.nibName, bundle: nil)
  428. collectionView?.register(editCellNib, forCellWithReuseIdentifier: editCell.defaultReuseIdentifier)
  429. }
  430. collectionView?.backgroundColor = PresentationTheme.current.colors.background
  431. collectionView?.alwaysBounceVertical = true
  432. longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongGesture(gesture:)))
  433. collectionView?.addGestureRecognizer(longPressGesture)
  434. if #available(iOS 11.0, *) {
  435. collectionView?.contentInsetAdjustmentBehavior = .always
  436. // collectionView?.dragDelegate = dragAndDropManager
  437. // collectionView?.dropDelegate = dragAndDropManager
  438. }
  439. }
  440. @objc func handleLongGesture(gesture: UILongPressGestureRecognizer) {
  441. switch gesture.state {
  442. case .began:
  443. guard let selectedIndexPath = collectionView.indexPathForItem(at: gesture.location(in: collectionView)) else {
  444. break
  445. }
  446. collectionView.beginInteractiveMovementForItem(at: selectedIndexPath)
  447. case .changed:
  448. collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: gesture.view!))
  449. case .ended:
  450. collectionView.endInteractiveMovement()
  451. default:
  452. collectionView.cancelInteractiveMovement()
  453. }
  454. }
  455. }
  456. // MARK: - Player
  457. extension MediaCategoryViewController {
  458. func play(media: VLCMLMedia, at indexPath: IndexPath) {
  459. let playbackController = PlaybackService.sharedInstance()
  460. let autoPlayNextItem = UserDefaults.standard.bool(forKey: kVLCAutomaticallyPlayNextItem)
  461. playbackController.fullscreenSessionRequested = media.type() != .audio
  462. if !autoPlayNextItem {
  463. playbackController.play(media)
  464. return
  465. }
  466. var tracks = [VLCMLMedia]()
  467. if let model = model as? MediaCollectionModel {
  468. tracks = model.files() ?? []
  469. } else {
  470. tracks = (isSearching ? searchDataSource.searchData : model.anyfiles) as? [VLCMLMedia] ?? []
  471. }
  472. playbackController.playMedia(at: indexPath.row, fromCollection: tracks)
  473. }
  474. }