Advertisement
Guest User

Untitled

a guest
Nov 9th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 4.41 KB | None | 0 0
  1. /*****************************************************************************
  2.  * VLCMediaList.m: VLCKit.framework VLCMediaList implementation
  3.  *****************************************************************************
  4.  * Copyright (C) 2018 David Cordero
  5.  * $Id$
  6.  *
  7.  * Authors: David Cordero <david # corderoramirez.com>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify it
  10.  * under the terms of the GNU Lesser General Public License as published by
  11.  * the Free Software Foundation; either version 2.1 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17.  * GNU Lesser General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU Lesser General Public License
  20.  * along with this program; if not, write to the Free Software Foundation,
  21.  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23.  
  24. import UIKit
  25.  
  26. class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
  27.  
  28.     var videoView: UIView!
  29.     var tableView:UITableView!
  30.     var stations = [String]()
  31.     var urls = [String]()
  32.  
  33.     private var mediaPlayer: VLCMediaPlayer!
  34.  
  35.     override func viewDidLoad() {
  36.         super.viewDidLoad()
  37.  
  38.         videoView = UIView(frame: view.bounds)
  39.         mediaPlayer = VLCMediaPlayer()
  40.         mediaPlayer.drawable = view
  41.         //mediaPlayer.media = VLCMedia(url: URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!)
  42.         //mediaPlayer.play()
  43.        
  44.        
  45.         stations = ["big_buck_bunny","Animals","Free","YouTube","Favorites","Paid"]
  46.         urls = ["https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", "https://staging.coverr.co/s3/mp4/Fetcher.mp4"]
  47.         setUpTableView()
  48.     }
  49.    
  50.     func setUpTableView(){
  51.        
  52.         let tableFrame:CGRect = CGRect(x: 0, y: 120, width: (self.view.frame.width / 3)-50 , height: self.view.frame.height-450)
  53.         tableView = UITableView(frame: tableFrame, style: .grouped)
  54.         view.addSubview(tableView)
  55.        
  56.         self.tableView.dataSource = self
  57.         self.tableView.delegate = self
  58.        
  59.        
  60.     }
  61.    
  62.     func numberOfSections(in tableView: UITableView) -> Int {
  63.         //1 column
  64.         return 1
  65.     }
  66.    
  67.     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  68.        
  69.         return stations.count
  70.        
  71.     }
  72.    
  73.     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  74.        
  75.         let cell = UITableViewCell(style:  .subtitle, reuseIdentifier: nil)
  76.         cell.textLabel?.text = "\( stations[indexPath.row] )"
  77.        
  78.         return cell
  79.     }
  80.    
  81.    
  82.     func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
  83.         //this runs on press
  84.         print (indexPath.item)
  85.         print( stations[indexPath.item] )
  86.         mediaPlayer.media = VLCMedia(url: URL(string: urls[indexPath.item])!)
  87.         mediaPlayer.play()
  88.         mediaPlayer.brightness
  89.        
  90.     }
  91.    
  92.     func tableView(_ tableView: UITableView, didUpdateFocusIn context: UITableViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
  93.        
  94.         //runs anytime we move up or down the table view
  95.         //
  96.        
  97.         if ( context.nextFocusedIndexPath == nil){
  98.             print ("not browsing the table")
  99.             return
  100.         }
  101.        
  102.         print ( context.nextFocusedIndexPath!.item )
  103.         //use that number to populate something else probably according to the category.
  104.        
  105.     }
  106.    
  107.    
  108.    
  109.     override func didReceiveMemoryWarning() {
  110.         super.didReceiveMemoryWarning()
  111.         // Dispose of any resources that can be recreated.
  112.     }
  113.  
  114.     override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
  115.  
  116.         for press in presses {
  117.             switch press.type {
  118.             case .playPause:
  119.                 if mediaPlayer.isPlaying {
  120.                     mediaPlayer.pause()
  121.                 }
  122.                 else {
  123.                     mediaPlayer.play()
  124.                 }
  125.             default: ()
  126.             }
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement