Skip to content

scade-platform/FusionMedia

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

FusionMedia

FusionMedia helps to integrate the media player to play the media files.

gif

Add it to the Package.swift

dependencies: [
    .package(
      name: "FusionMedia", url: "https://github.com/scade-platform/FusionMedia.git", .branch("main")
    ),
    .package(
      name: "ScadeExtensions", url: "https://github.com/scade-platform/ScadeExtensions.git",
      .branch("main")),
  ],
  targets: [
    .target(
      name: "FusionAudioPlayerDemo",
      dependencies: [
        .product(name: "FusionMedia", package: "FusionMedia"),
        .product(name: "ScadeExtensions", package: "ScadeExtensions"),
      ],
      exclude: ["main.page"],
      swiftSettings: [
        .unsafeFlags(["-F", SCADE_SDK], .when(platforms: [.macOS, .iOS])),
        .unsafeFlags(["-I", "\(SCADE_SDK)/include"], .when(platforms: [.android])),
      ]
    )
  ]

Import & Use FusionMedia

  var player: FusionMedia.AudioPlayer?
  
  let playImage = "./Assets/play1.svg"
  let stopImage = "./Assets/stop1.svg"
  let maxVolume = 100
  var duration: Double = 180
  var timer: Timer!
    //setup player
 self.player = FusionMedia.AudioPlayer(url: URL(forResource: "Assets/Ketsa-Good_Vibe.mp3"))

Setup the Slider to navigate to the play track

// setup slider
    if let player = self.player {
      self.positionSlide.maxValue = Int(player.duration)
      self.volumeSlide.maxValue = maxVolume
      self.volumeSlide.position = Int(player.volume * Float(maxVolume))
    }
    self.positionSlide.onSlide { e in self.onPositionChanged(ev: e) }
    self.volumeSlide.onSlide { e in self.onVolumeChanged(ev: e) }

    // setup stop/play button
    self.playStopButton.onClick { _ in self.playStopButtonClicked() }
  func onPositionChanged(ev: SCDWidgetsSliderLineEvent?) {
    let sliderPosition = Double(ev!.newValue)
      player?.seek(to: sliderPosition)
  }

Change Volume level

  func onVolumeChanged(ev: SCDWidgetsSliderLineEvent?) {
    let sliderPosition = ev!.newValue

    player?.volume = Float(sliderPosition) / Float(self.maxVolume)
  }

Stop the Media Player

 func playStopButtonClicked() {

    guard let player = player else { return }

    // toggle state and change button accordingly

    let imageUrl = player.isPlaying ? playImage : stopImage
    self.playStopButton.url = imageUrl
    player.isPlaying ? player.stop() : player.play()

    timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in
      self.positionSlide.position = Int(player.currentTime)
      if !player.isPlaying {
        timer.invalidate()
      }
    }
  }

Contribution

Consider contributing by creating a pull request (PR) or opening an issue. By creating an issue, you can alert the repository's maintainers to any bugs or missing documentation you've found. πŸ›πŸ“ If you're feeling confident and want to make a bigger impact, creating a PR, can be a great way to help others. πŸ“–πŸ’‘ Remember, contributing to open source is a collaborative effort, and any contribution, big or small, is always appreciated! πŸ™Œ So why not take the first step and start contributing today? 😊

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •