12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- //
- // AudioViewController.swift
- // LMS
- //
- // Created by Suraj Kumar Mandal on 24/08/22.
- //
- import UIKit
- import SideMenu
- import AVFoundation
- class AudioViewController: UIViewController {
-
- @IBOutlet var navigationBar: UINavigationBar!
- @IBOutlet var currentTimeLabel: UILabel!
- @IBOutlet var totalTimeLabel: UILabel!
- @IBOutlet var progressSlider: UISlider!
- @IBOutlet var backwardButton: UIButton!
- @IBOutlet var playButton: UIButton!
- @IBOutlet var forwardButton: UIButton!
-
- var pageName = String()
- var fileId = String()
-
- var player:AVPlayer?
- var playerItem:AVPlayerItem?
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- // Do any additional setup after loading the view.
- navigationBar.topItem?.title = pageName
- }
-
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
-
- let url = URL(string: "http://3.7.239.194:8080/\(fileId).mp3")
- let playerItem:AVPlayerItem = AVPlayerItem(url: url!)
- player = AVPlayer(playerItem: playerItem)
-
- let playerLayer=AVPlayerLayer(player: player!)
- playerLayer.frame = CGRect(x:0, y:0, width:10, height:50)
- self.view.layer.addSublayer(playerLayer)
- }
-
-
- /*
- // MARK: - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
-
- @IBAction func backAction(_ sender: UIBarButtonItem) {
- self.navigationController?.popViewController(animated: true)
- }
-
- @IBAction func playAction(_ sender: UIButton) {
- if player?.rate == 0 {
- player!.play()
- playButton.setImage(UIImage(named: "pause"), for: .normal)
- } else {
- player!.pause()
- playButton.setImage(UIImage(named: "play-button-arrowhead"), for: .normal)
- }
- }
-
- @IBAction func progressAction(_ sender: UISlider) {
- let seconds : Int64 = Int64(sender.value)
- let targetTime:CMTime = CMTimeMake(value: seconds, timescale: 1)
- player!.seek(to: targetTime)
- if player!.rate == 0 {
- player?.play()
- }
- }
-
-
- }
|