我按照http://mongodb.github.io/mongo-scala-driver/的说明安装了scala 2.11。但我的第一堂课无法参加。
import UIKit
import AVFoundation
class ViewController: UIViewController, AVAudioPlayerDelegate,
AVAudioRecorderDelegate {
var audioPlayer: AVAudioPlayer?
var audioRecorder: AVAudioRecorder?
@IBOutlet weak var recordAudio: UIButton!
@IBOutlet weak var stopAudio: UIButton!
@IBOutlet weak var playAudio: UIButton!
var arrayData: [FileManager] = []
override func viewDidLoad() {
super.viewDidLoad()
playAudio.isEnabled = false
stopAudio.isEnabled = false
// Creating File Manager
let fileMgr = FileManager.default
let dirPath = fileMgr.urls(for: .documentDirectory, in: .userDomainMask)
let soundFileUrl = dirPath[0].appendingPathComponent("sound.caf")
let recordSettings = [AVEncoderAudioQualityKey: AVAudioQuality.min.rawValue,
AVEncoderBitRateKey: 16,
AVNumberOfChannelsKey: 2,
AVSampleRateKey: 44100.0 ] as [String:Any]
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
} catch {
print(error.localizedDescription)
}
do {
try audioRecorder = AVAudioRecorder(url: soundFileUrl, settings: recordSettings as [String : Any])
audioRecorder?.prepareToRecord()
} catch {
print(error.localizedDescription)
}
}
@IBAction func recordButton(_ sender: Any) {
if audioRecorder?.isRecording == false {
playAudio.isEnabled = false
stopAudio.isEnabled = true
audioRecorder?.record()
}
}
@IBAction func stopButton(_ sender: Any) {
stopAudio.isEnabled = false
playAudio.isEnabled = true
recordAudio.isEnabled = true
if audioRecorder?.isRecording == true{
audioRecorder?.stop()
} else {
audioPlayer?.stop()
}
}
@IBAction func playButton(_ sender: Any) {
if audioRecorder?.isRecording == false{
stopAudio.isEnabled = true
recordAudio.isEnabled = true
do {
try audioPlayer = AVAudioPlayer(contentsOf: (audioRecorder?.url)!)
audioPlayer!.delegate = self
audioPlayer!.prepareToPlay()
audioPlayer!.play()
} catch {
print(error.localizedDescription)
}
}
}
func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
recordAudio.isEnabled = true
stopAudio.isEnabled = false
}
func audioPlayerDecodeErrorDidOccur(_ player: AVAudioPlayer, error: Error?) {
print("Audio Player Error")
}
func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) {
}
func audioRecorderEncodeErrorDidOccur(_ recorder: AVAudioRecorder, error: Error?) {
print("Audio Recorder Error")
}
例外:
def main(args: Array[String]): Unit = {
val mongoClient: MongoClient = if (args.isEmpty) MongoClient() else MongoClient("mongodb://localhost")
}
答案 0 :(得分:1)
我遇到了同样的问题,这是由于对底层Java驱动程序的错误依赖。 Mongo Spark连接器依赖于Java驱动程序的3.2.2版本,显然Scala驱动程序也使用了该驱动程序。我通过在sbt:
中定义依赖关系解决了这个问题val mongoScalaDriver = "org.mongodb.scala" %% "mongo-scala-driver" % "2.1.0"
val mongoJavaDriver = "org.mongodb" % "mongo-java-driver" % "3.4.2"
val mongoSpark = Seq(mongoScalaDriver, mongoJavaDriver, "org.mongodb.spark" %% "mongo-spark-connector" % "2.0.0")
我在我的图书馆项目中使用了mongoSpark。另外,我明确地添加了对Java驱动程序版本3.4.2的依赖。
答案 1 :(得分:0)
我终于通过build.sbt中的一行来修复了这个问题:
<script src="https://unpkg.com/vue@2.4.2/dist/vue.min.js"></script>
<div id="app">
<transition name="highlight" mode="out-in">
<h1 :key="rank">Current Rank: <strong>{{ rank }}</strong></h1>
</transition>
<p>Your XP: <strong>{{ xp }}</strong></p>
<button @click="increase">+ 10 XP</button>
<button @click="decrease">- 10 XP</button>
</div>