Skip to content

Commit

Permalink
Merge pull request #42 from yoheimuta/set-default-metadata-without-do…
Browse files Browse the repository at this point in the history
…wnloading

Set default metadata without downloading
  • Loading branch information
yoheimuta committed Oct 7, 2021
2 parents b8bfb65 + 00ef3c1 commit 4f18527
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
16 changes: 13 additions & 3 deletions Example/TableViewController.swift
Expand Up @@ -5,6 +5,7 @@
// Created by YOSHIMUTA YOHEI on 2019/09/12.
// Copyright © 2019 YOSHIMUTA YOHEI. All rights reserved.
//
// swiftlint:disable line_length

import RxCocoa
import RxMusicPlayer
Expand Down Expand Up @@ -35,15 +36,24 @@ class TableViewController: UITableViewController {
super.viewDidLoad()

// 1) Create a player
let items = [
var items = [
"https://storage.googleapis.com/great-dev/oss/musicplayer/tagmp3_1473200_1.mp3",
"https://storage.googleapis.com/great-dev/oss/musicplayer/tagmp3_2160166.mp3",
"https://storage.googleapis.com/great-dev/oss/musicplayer/tagmp3_4690995.mp3",
"https://storage.googleapis.com/great-dev/oss/musicplayer/tagmp3_9179181.mp3",
"https://storage.googleapis.com/great-dev/oss/musicplayer/bensound-extremeaction.mp3",
"https://storage.googleapis.com/great-dev/oss/musicplayer/bensound-littleplanet.mp3",
]
.map({ RxMusicPlayerItem(url: URL(string: $0)!) })
// The default metadata is ignored since this item's original metadata are set already.
items.append(RxMusicPlayerItem(url: URL(string: "https://storage.googleapis.com/great-dev/oss/musicplayer/bensound-extremeaction.mp3")!,
meta: RxMusicPlayerItem.Meta(title: "defaultTitle",
album: "defaultAlbum",
artist: "defaultArtist",
skipDownloading: false)))
// The default metadata is used since this item's original metadata are empty.
items.append(RxMusicPlayerItem(url: URL(string: "https://storage.googleapis.com/great-dev/oss/musicplayer/bensound-littleplanet.mp3")!,
meta: RxMusicPlayerItem.Meta(title: "defaultTitle",
album: "defaultAlbum",
artist: "defaultArtist")))
let player = RxMusicPlayer(items: Array(items[0 ..< 4]))!

// 2) Control views
Expand Down
2 changes: 0 additions & 2 deletions RxMusicPlayer.xcodeproj/project.pbxproj
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
26BC08410487D678000C1FD8 /* Pods_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B9F36DF15A393FC092613E9 /* Pods_Example.framework */; };
C23F042D262C40D4004686CE /* RxSwift.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2A64DB9262C3EB40018641C /* RxSwift.xcframework */; };
C23F042E262C40D4004686CE /* RxSwift.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C2A64DB9262C3EB40018641C /* RxSwift.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
C23F043B262C4183004686CE /* RxSwift.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2A64DB9262C3EB40018641C /* RxSwift.xcframework */; };
Expand Down Expand Up @@ -245,7 +244,6 @@
C23F0446262C4228004686CE /* RxCocoa.xcframework in Frameworks */,
C23F0452262C428F004686CE /* RxRelay.xcframework in Frameworks */,
FF11FBF92329E50E0043C29B /* RxMusicPlayer.framework in Frameworks */,
26BC08410487D678000C1FD8 /* Pods_Example.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
9 changes: 5 additions & 4 deletions RxMusicPlayer/RxMusicPlayerItem.swift
Expand Up @@ -27,23 +27,24 @@ open class RxMusicPlayerItem: NSObject {

/**
Initialize Metadata with a prefetched one.
If one of the arguments is not nil, the player will skip downloading the metadata.
If skipDownloading is true, the player will use the given parameters, instead of downloading the metadata.
Otherwise, the player will download the metadata, and then use the given parameters as default values.
*/
public init(duration: CMTime? = nil,
lyrics: String? = nil,
title: String? = nil,
album: String? = nil,
artist: String? = nil,
artwork: UIImage? = nil) {
artwork: UIImage? = nil,
skipDownloading: Bool = false) {
self.duration = duration
self.lyrics = lyrics
self.title = title
self.album = album
self.artist = artist
self.artwork = artwork

if duration != nil || lyrics != nil || title != nil ||
album != nil || artist != nil || artist != nil {
if skipDownloading {
didAllSetRelay.accept(true)
}
}
Expand Down

0 comments on commit 4f18527

Please sign in to comment.