質問編集履歴
2
コードが長すぎるので一部削除しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -29,12 +29,6 @@
|
|
29
29
|
|
30
30
|
// soundIdからMediaItemを取得
|
31
31
|
let songId: NSNumber = albums[indexPath.row].songId
|
32
|
-
|
33
|
-
self.title = albums[indexPath.row].songTitle
|
34
|
-
|
35
|
-
// リストビューの破棄
|
36
|
-
self.dismiss(animated: true, completion: nil)
|
37
|
-
|
38
32
|
print("expotItemを呼び出します")
|
39
33
|
instanceOfObjcMethod.exportItem(toId: songId.description)
|
40
34
|
print("expotItemを呼び出し終わりました")
|
@@ -69,6 +63,7 @@
|
|
69
63
|
#import "ObjcSwift.h"
|
70
64
|
```
|
71
65
|
MusicLibraryMediaPicker.mm
|
66
|
+
全文だと長いので、関係ない部分を削除しております。
|
72
67
|
```Objective-C++
|
73
68
|
|
74
69
|
# import "ObjcSwift.h"
|
1
ソースコードの関係ない部分を削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
### 該当のソースコード
|
14
14
|
|
15
15
|
ViewController.swift
|
16
|
+
全文だと長いので、関係ない部分を削除しております。
|
16
17
|
```Objective-C++
|
17
18
|
//import Foundation
|
18
19
|
import UIKit
|
@@ -21,86 +22,8 @@
|
|
21
22
|
|
22
23
|
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
23
24
|
|
24
|
-
var myTableView: UITableView!
|
25
|
-
var albums: [SongInfo] = []
|
26
|
-
var songQuery: SongQuery = SongQuery()
|
27
25
|
let instanceOfObjcMethod: ObjcMethod = ObjcMethod()
|
28
|
-
var audio: AVAudioPlayer! = nil
|
29
26
|
|
30
|
-
weak var delegate: audiosend?
|
31
|
-
|
32
|
-
override func viewDidLoad() {
|
33
|
-
|
34
|
-
super.viewDidLoad()
|
35
|
-
|
36
|
-
albums = songQuery.get()
|
37
|
-
if(albums.count == 0){
|
38
|
-
self.dismiss(animated: true, completion: nil)
|
39
|
-
return;
|
40
|
-
}
|
41
|
-
|
42
|
-
let barHeight: CGFloat = UIApplication.shared.statusBarFrame.size.height
|
43
|
-
let displayWidth: CGFloat = self.view.frame.width
|
44
|
-
let displayHeight: CGFloat = self.view.frame.height
|
45
|
-
|
46
|
-
let leftButton = UIBarButtonItem(title: "戻る", style: UIBarButtonItem.Style.plain, target: self, action: #selector(goTop))
|
47
|
-
self.navigationItem.leftBarButtonItem = leftButton
|
48
|
-
|
49
|
-
myTableView = UITableView(frame: CGRect(x: 0, y: barHeight, width: displayWidth, height: displayHeight))
|
50
|
-
|
51
|
-
self.title = "Songs"
|
52
|
-
|
53
|
-
self.myTableView.register(UITableViewCell.self, forCellReuseIdentifier: "MyCell")
|
54
|
-
self.myTableView.delegate = self
|
55
|
-
self.myTableView.dataSource = self
|
56
|
-
self.view.addSubview(self.myTableView)
|
57
|
-
print(">>> viewDidLoad")
|
58
|
-
}
|
59
|
-
|
60
|
-
// 選曲時のリストビューを破棄(戻るボタン用)
|
61
|
-
@objc func goTop() {
|
62
|
-
self.dismiss(animated: true, completion: nil)
|
63
|
-
instanceOfObjcMethod.setDoDisplay(_: nil)
|
64
|
-
}
|
65
|
-
|
66
|
-
// メモリピンチの時
|
67
|
-
override func didReceiveMemoryWarning() {
|
68
|
-
super.didReceiveMemoryWarning()
|
69
|
-
}
|
70
|
-
// sectionの数を返す
|
71
|
-
func numberOfSectionsInTableView( in tableView: UITableView! ) -> Int {
|
72
|
-
return albums.count
|
73
|
-
}
|
74
|
-
|
75
|
-
// 各sectionのitem数を返す
|
76
|
-
func tableView( _ tableView: UITableView, numberOfRowsInSection section: Int ) -> Int {
|
77
|
-
return albums.count
|
78
|
-
}
|
79
|
-
|
80
|
-
func tableView( _ tableView: UITableView, cellForRowAt indexPath : IndexPath) -> UITableViewCell {
|
81
|
-
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath as IndexPath)
|
82
|
-
cell.textLabel!.text = albums[indexPath.row].songTitle
|
83
|
-
// 曲検索
|
84
|
-
let property = MPMediaPropertyPredicate(value: albums[indexPath.row].songId, forProperty: MPMediaItemPropertyPersistentID)
|
85
|
-
let query = MPMediaQuery()
|
86
|
-
query.addFilterPredicate(property)
|
87
|
-
let single = query.items!
|
88
|
-
// セルに画像を入れる
|
89
|
-
if let image = single.first!.artwork?.image(at: CGSize(width: 40, height: 40)) {
|
90
|
-
cell.imageView!.image = image
|
91
|
-
} else {
|
92
|
-
let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
|
93
|
-
let imagePath = "(documentPath)/default_artwork.jpg"
|
94
|
-
if let data = FileManager.default.contents(atPath: imagePath) { cell.imageView?.image = UIImage(data: data) }
|
95
|
-
}
|
96
|
-
return cell;
|
97
|
-
}
|
98
|
-
|
99
|
-
// sectionのタイトル
|
100
|
-
func tableView( _ tableView: UITableView, titleForHeaderInSection section: Int ) -> String? {
|
101
|
-
return ""
|
102
|
-
}
|
103
|
-
|
104
27
|
// 選択した音楽を再生
|
105
28
|
func tableView( _ tableView: UITableView, didSelectRowAt indexPath:IndexPath ) {
|
106
29
|
|
@@ -147,15 +70,6 @@
|
|
147
70
|
```
|
148
71
|
MusicLibraryMediaPicker.mm
|
149
72
|
```Objective-C++
|
150
|
-
# import <Foundation/Foundation.h>
|
151
|
-
# import <MediaPlayer/MediaPlayer.h>
|
152
|
-
# import <AVFoundation/AVAudioFile.h>
|
153
|
-
# import <AVFoundation/AVAudioEngine.h>
|
154
|
-
# import <AVFoundation/AVFoundation.h>
|
155
|
-
# import <AVFoundation/AVAssetReader.h>
|
156
|
-
# import <AVFoundation/AVAssetWriter.h>
|
157
|
-
# import <QuartzCore/QuartzCore.h>
|
158
|
-
# import <AudioToolBox/AudioToolBox.h>
|
159
73
|
|
160
74
|
# import "ObjcSwift.h"
|
161
75
|
|