質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift 2

Swift 2は、Apple社が独自に開発を行っている言語「Swift」のアップグレード版です。iOSやOS X、さらにLinuxにも対応可能です。また、throws-catchベースのエラーハンドリングが追加されています。

Q&A

解決済

1回答

2012閲覧

(swift2)ボタンを押すと音が出るアプリのコードでエラーが出る。。。

shun_oga

総合スコア12

Swift 2

Swift 2は、Apple社が独自に開発を行っている言語「Swift」のアップグレード版です。iOSやOS X、さらにLinuxにも対応可能です。また、throws-catchベースのエラーハンドリングが追加されています。

0グッド

1クリップ

投稿2015/11/11 14:12

ボタンを押すと音楽が流れるアプリを練習で開発しています。
以下のコードを書いたのですが、太字部分でエラーが出てしいます。原因がわかる方教えていただければ幸いです。

import UIKit
import AVFoundation

class ViewController: UIViewController {

**var practiceSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(“TwinkleLittleStar″, ofType: “mp3″)!)** var practicePlayer = AVAudioPlayer() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. practicePlayer = AVAudioPlayer(contentsOfURL: practiceSound, error: nil) practicePlayer.prepareToPlay() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func TwinkleLittleStar(sender: UIButton) { practicePlayer.currentTime = 0 practicePlayer.play() }

}

なお、エラーの内容は
Unicode curly quote found,replace with ""
Expected ',' separator

の2つです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

ダブルクォーテーションが全角文字になっていますので半角文字にして下さい。

swift

1("TwinkleLittleStar", ofType: "mp3")

投稿2015/11/11 16:51

fuzzball

総合スコア16731

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

shun_oga

2015/11/12 16:51

ありがとうございます。修正し、また、 practicePlayer = AVAudioPlayer(contentsOfURL: practiceSound, error: nil) の部分を前回質問させていただいた内容を参考に、do~catch~try~の形に修正しました。 しかし、下のコードの部分でエラーが出ます。 var practiceSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("TwinkleLittleStar", ofType: "mp3")!) エラー内容は、EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP,subcode=0x0) です。 どう修正すればよいのかググってみたのですがわからず再度質問させていただきます。もしわかれば教えていただければ幸いです。よろしくお願いします。 以下、コードの全体です。 import UIKit import AVFoundation class ViewController: UIViewController { var practiceSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("TwinkleLittleStar", ofType: "mp3")!) var practicePlayer = AVAudioPlayer() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. do { let practicePlayer = try AVAudioPlayer(contentsOfURL: practiceSound) practicePlayer.prepareToPlay() } catch { print("error") } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func TwinkleLittleStar(sender: UIButton) { practicePlayer.currentTime = 0 practicePlayer.play() } }
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問