Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
VLC-iOS
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
264
Issues
264
List
Boards
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VideoLAN
VLC-iOS
Commits
4c0b3c8d
Commit
4c0b3c8d
authored
Jul 26, 2018
by
Soomin Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
VLCMediaLibraryManager: Add observation
parent
488184d9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
131 deletions
+33
-131
SharedSources/VLCMediaLibraryManager.swift
SharedSources/VLCMediaLibraryManager.swift
+33
-131
No files found.
SharedSources/VLCMediaLibraryManager.swift
View file @
4c0b3c8d
...
...
@@ -10,12 +10,24 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
@objc
protocol
MediaLibraryObserver
:
class
{
@objc
optional
func
medialibrary
(
_
medialibrary
:
VLCMediaLibraryManager
,
didUpdateVideo
video
:
[
VLCMLMedia
])
@objc
optional
func
medialibrary
(
_
medialibrary
:
VLCMediaLibraryManager
,
didAddVideo
video
:
[
VLCMLMedia
])
}
class
VLCMediaLibraryManager
:
NSObject
{
private
static
let
databaseName
:
String
=
"medialibrary.db"
private
var
databasePath
:
String
!
private
var
thumbnailPath
:
String
!
// Using ObjectIdentifier to avoid duplication and facilitate
// identification of observing object
private
var
observers
=
[
ObjectIdentifier
:
Observer
]()
private
lazy
var
medialib
:
VLCMediaLibrary
=
{
let
medialibrary
=
VLCMediaLibrary
()
medialibrary
.
delegate
=
self
...
...
@@ -88,139 +100,27 @@ class VLCMediaLibraryManager: NSObject {
}
}
// MARK: MediaDataSource - Other methods
// MARK: - Observer
private
extension
VLCMediaLibraryManager
{
struct
Observer
{
weak
var
observer
:
MediaLibraryObserver
?
init
(
_
observer
:
MediaLibraryObserver
)
{
self
.
observer
=
observer
}
}
}
extension
VLCMediaLibraryManager
{
// @objc enum VLCMediaCategory: Int {
// case unknown
// case audio
// case video
// }
//
// @objc enum VLCMediaSubcategory: Int {
// case unknown
// case movies
// case episodes
// case artists
// case albums
// case tracks
// case genres
// case videoPlaylists
// case audioPlaylists
// case allVideos
// }
//
// struct VLCMediaType {
// let category: VLCMediaCategory
// var subcategory: VLCMediaSubcategory
// }
//
//
// var foundVideos = [VLCMLMedia]()
// var foundAudio = [VLCMLMedia]()
//
// var movies = [VLCMLMedia]()
// var episodes = [VLCMLMedia]()
// var artists = [String]()
// var albums = [MLAlbum]()
// var genres = [String]()
// var audioPlaylist = [MLLabel]()
// var videoPlaylist = [MLLabel]()
//
func
addObserver
(
_
observer
:
MediaLibraryObserver
)
{
let
identifier
=
ObjectIdentifier
(
observer
)
observers
[
identifier
]
=
Observer
(
observer
)
}
// @objc func numberOfFiles(subcategory: VLCMediaSubcategory) -> Int {
// return array(for: subcategory).countSources/MediaViewController.swift
// }
//
// private func array(for subcategory: VLCMediaSubcategory) -> [Any] {
// switch subcategory {
// case .unknown:
// preconditionFailure("No")
// case .movies:
// return movies
// case .episodes:
// return episodes
// case .artists:
// return artists
// case .albums:
// return albums
// case .tracks:
// return foundAudio
// case .genres:
// return genres
// case .audioPlaylists:
// return audioPlaylist
// case .videoPlaylists:
// return videoPlaylist
// case .allVideos:
// return foundVideos
// }
// }
//
// func indicatorInfo(for subcategory: VLCMediaSubcategory) -> IndicatorInfo {
// switch subcategory {
// case .unknown:
// preconditionFailure("No")
// case .movies:
// return IndicatorInfo(title: NSLocalizedString("MOVIES", comment: ""))
// case .episodes:
// return IndicatorInfo(title: NSLocalizedString("EPISODES", comment: ""))
// case .artists:
// return IndicatorInfo(title: NSLocalizedString("ARTISTS", comment: ""))
// case .albums:
// return IndicatorInfo(title: NSLocalizedString("ALBUMS", comment: ""))
// case .tracks:
// return IndicatorInfo(title: NSLocalizedString("SONGS", comment: ""))
// case .genres:
// return IndicatorInfo(title: NSLocalizedString("GENRES", comment: ""))
// case .audioPlaylists:
// return IndicatorInfo(title: NSLocalizedString("AUDIO_PLAYLISTS", comment: ""))
// case .videoPlaylists:
// return IndicatorInfo(title: NSLocalizedString("VIDEO_PLAYLISTS", comment: ""))
// case .allVideos:
// return IndicatorInfo(title: NSLocalizedString("VIDEOS", comment: ""))
// }
//
// }
//
// @objc func object(at index: Int, subcategory: VLCMediaSubcategory) -> Any {
//
// guard index >= 0 else {
// preconditionFailure("a negative value ? I don't think so!")
// }
//
// let categoryArray = array(for: subcategory)
// if index < categoryArray.count {
// return categoryArray[Int(index)]
// }
// preconditionFailure("index is taller than count")
// }
//
// func allObjects(for subcategory: VLCMediaSubcategory) -> [Any] {
// return array(for:subcategory)
// }
//
// func removeObject(at index: Int, subcategory: VLCMediaSubcategory) {
// guard index >= 0 else {
// preconditionFailure("a negative value ? I don't think so!")
// }
// var categoryArray = array(for: subcategory)
// if index < categoryArray.count {
// categoryArray.remove(at: index)
// }
// preconditionFailure("index is taller than count")
// }
//
// func insert(_ item: MLFile, at index: Int, subcategory: VLCMediaSubcategory) {
// guard index >= 0 else {
// preconditionFailure("a negative value ? I don't think so!")
// }
// var categoryArray = array(for: subcategory)
// if index < categoryArray.count {
// categoryArray.insert(item, at: index)
// }
// categoryArray.append(item)
// }
func
removeObserver
(
_
observer
:
MediaLibraryObserver
)
{
let
identifier
=
ObjectIdentifier
(
observer
)
observers
.
removeValue
(
forKey
:
identifier
)
}
}
// MARK: MediaDataSource - Audio methods
...
...
@@ -298,7 +198,9 @@ extension VLCMediaLibraryManager {
// MARK: VLCMediaLibraryDelegate
extension
VLCMediaLibraryManager
:
VLCMediaLibraryDelegate
{
func
medialibrary
(
_
medialibrary
:
VLCMediaLibrary
,
didAddMedia
media
:
[
VLCMLMedia
])
{
NotificationCenter
.
default
.
post
(
name
:
.
VLCVideosDidChangeNotification
,
object
:
media
)
for
observer
in
observers
{
observer
.
value
.
observer
?
.
medialibrary
!
(
self
,
didAddVideo
:
media
)
}
}
func
medialibrary
(
_
medialibrary
:
VLCMediaLibrary
,
didStartDiscovery
entryPoint
:
String
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment