Unknown selected data source for Port Speaker (type: Speaker)?












18















i am getting this message in cat log multiple times :



[avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)


i am using this code to playback background music :



  let path = Bundle.main.path(forResource: fileName, ofType:"mp3")!
let url = URL(fileURLWithPath: path)

do {
let sound = try AVAudioPlayer(contentsOf: url)
self.player = sound
sound.prepareToPlay()
sound.volume = 0.05
sound.numberOfLoops = loops
sound.play()
} catch {
print("[PLAY SOUND][DELEGATE] error loading file -> (fileName)")
}


i made a research and i found similar issues so i've added the audio category in viewdidload :



  do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}


after i've added the above code , the background music is playing even if the phone on silent mode ! and the debugger message for Unknown selected data source for Port Speaker (type: Speaker) is still showing










share|improve this question























  • To stop the sound from playing when the device is on Silent or switched to silent change AVAudioSessionCategoryPlayback to AVAudioSessionCategoryAmbient

    – Hasti Ranjkesh
    Oct 16 '18 at 14:00


















18















i am getting this message in cat log multiple times :



[avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)


i am using this code to playback background music :



  let path = Bundle.main.path(forResource: fileName, ofType:"mp3")!
let url = URL(fileURLWithPath: path)

do {
let sound = try AVAudioPlayer(contentsOf: url)
self.player = sound
sound.prepareToPlay()
sound.volume = 0.05
sound.numberOfLoops = loops
sound.play()
} catch {
print("[PLAY SOUND][DELEGATE] error loading file -> (fileName)")
}


i made a research and i found similar issues so i've added the audio category in viewdidload :



  do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}


after i've added the above code , the background music is playing even if the phone on silent mode ! and the debugger message for Unknown selected data source for Port Speaker (type: Speaker) is still showing










share|improve this question























  • To stop the sound from playing when the device is on Silent or switched to silent change AVAudioSessionCategoryPlayback to AVAudioSessionCategoryAmbient

    – Hasti Ranjkesh
    Oct 16 '18 at 14:00
















18












18








18


7






i am getting this message in cat log multiple times :



[avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)


i am using this code to playback background music :



  let path = Bundle.main.path(forResource: fileName, ofType:"mp3")!
let url = URL(fileURLWithPath: path)

do {
let sound = try AVAudioPlayer(contentsOf: url)
self.player = sound
sound.prepareToPlay()
sound.volume = 0.05
sound.numberOfLoops = loops
sound.play()
} catch {
print("[PLAY SOUND][DELEGATE] error loading file -> (fileName)")
}


i made a research and i found similar issues so i've added the audio category in viewdidload :



  do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}


after i've added the above code , the background music is playing even if the phone on silent mode ! and the debugger message for Unknown selected data source for Port Speaker (type: Speaker) is still showing










share|improve this question














i am getting this message in cat log multiple times :



[avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)


i am using this code to playback background music :



  let path = Bundle.main.path(forResource: fileName, ofType:"mp3")!
let url = URL(fileURLWithPath: path)

do {
let sound = try AVAudioPlayer(contentsOf: url)
self.player = sound
sound.prepareToPlay()
sound.volume = 0.05
sound.numberOfLoops = loops
sound.play()
} catch {
print("[PLAY SOUND][DELEGATE] error loading file -> (fileName)")
}


i made a research and i found similar issues so i've added the audio category in viewdidload :



  do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}


after i've added the above code , the background music is playing even if the phone on silent mode ! and the debugger message for Unknown selected data source for Port Speaker (type: Speaker) is still showing







swift xcode audio






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 3 '18 at 11:40









JackJack

10.1k72360




10.1k72360













  • To stop the sound from playing when the device is on Silent or switched to silent change AVAudioSessionCategoryPlayback to AVAudioSessionCategoryAmbient

    – Hasti Ranjkesh
    Oct 16 '18 at 14:00





















  • To stop the sound from playing when the device is on Silent or switched to silent change AVAudioSessionCategoryPlayback to AVAudioSessionCategoryAmbient

    – Hasti Ranjkesh
    Oct 16 '18 at 14:00



















To stop the sound from playing when the device is on Silent or switched to silent change AVAudioSessionCategoryPlayback to AVAudioSessionCategoryAmbient

– Hasti Ranjkesh
Oct 16 '18 at 14:00







To stop the sound from playing when the device is on Silent or switched to silent change AVAudioSessionCategoryPlayback to AVAudioSessionCategoryAmbient

– Hasti Ranjkesh
Oct 16 '18 at 14:00














2 Answers
2






active

oldest

votes


















16





+50









The message Unknown selected data source for Port Speaker seems to be a problem with iOS 12. Apparently it's some warning that appears even if the code is working. Perhaps Apple will fix this soon, so maybe for now you can ignore this warning and once they find a solution you will be able to silence it.



Source: AVAudioSession errors in iOS 12



As for the background music playing on silent mode, it's because of the AVAudioSessionCategory you selected. According to AVAudioSessionCategoryPlayback documentation (source):




When using this category, your app audio continues with the Silent switch set to silent or when the screen locks.




Depending on the style of your app, maybe you could use AVAudioSessionCategorySoloAmbient (source):




Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).




Or maybe AVAudioSessionCategoryAmbient (source):




This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays while the Music app is playing. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).







share|improve this answer
























  • I tried this did not work for me but I am also not trying to play back music. The only place I am getting this message is when AdMod tries to display an ad which means I am getting it a lot. If the above is the correct answer it should shutdown this message in all cases since all other attempts to ask this question have been labeled duplicates and referred to this answer.

    – Sojourner9
    Oct 24 '18 at 21:42











  • @Sojourner9 for what I've read on the Apple Developer forums it seems to be a problem specific to iOS 12. Since the message comes from iOS, haven't found a way to silence it. That's why I mentioned that perhaps Apple will fix this soon. Maybe AdMob is trying to play a sound or a video so it's triggering this message? Are you using iOS 12 too?

    – Victor Sanchez
    Oct 26 '18 at 3:24



















2














From Swift 4.2, I originally had it set up like this:



try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: )


I didn't actually need recording capabilities, so I changed it to



try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: )


This removed the error (and was the only thing I could do to get the error gone). However, if you need recording capabilities as well, obviously this won't work.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52626252%2funknown-selected-data-source-for-port-speaker-type-speaker%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    16





    +50









    The message Unknown selected data source for Port Speaker seems to be a problem with iOS 12. Apparently it's some warning that appears even if the code is working. Perhaps Apple will fix this soon, so maybe for now you can ignore this warning and once they find a solution you will be able to silence it.



    Source: AVAudioSession errors in iOS 12



    As for the background music playing on silent mode, it's because of the AVAudioSessionCategory you selected. According to AVAudioSessionCategoryPlayback documentation (source):




    When using this category, your app audio continues with the Silent switch set to silent or when the screen locks.




    Depending on the style of your app, maybe you could use AVAudioSessionCategorySoloAmbient (source):




    Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).




    Or maybe AVAudioSessionCategoryAmbient (source):




    This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays while the Music app is playing. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).







    share|improve this answer
























    • I tried this did not work for me but I am also not trying to play back music. The only place I am getting this message is when AdMod tries to display an ad which means I am getting it a lot. If the above is the correct answer it should shutdown this message in all cases since all other attempts to ask this question have been labeled duplicates and referred to this answer.

      – Sojourner9
      Oct 24 '18 at 21:42











    • @Sojourner9 for what I've read on the Apple Developer forums it seems to be a problem specific to iOS 12. Since the message comes from iOS, haven't found a way to silence it. That's why I mentioned that perhaps Apple will fix this soon. Maybe AdMob is trying to play a sound or a video so it's triggering this message? Are you using iOS 12 too?

      – Victor Sanchez
      Oct 26 '18 at 3:24
















    16





    +50









    The message Unknown selected data source for Port Speaker seems to be a problem with iOS 12. Apparently it's some warning that appears even if the code is working. Perhaps Apple will fix this soon, so maybe for now you can ignore this warning and once they find a solution you will be able to silence it.



    Source: AVAudioSession errors in iOS 12



    As for the background music playing on silent mode, it's because of the AVAudioSessionCategory you selected. According to AVAudioSessionCategoryPlayback documentation (source):




    When using this category, your app audio continues with the Silent switch set to silent or when the screen locks.




    Depending on the style of your app, maybe you could use AVAudioSessionCategorySoloAmbient (source):




    Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).




    Or maybe AVAudioSessionCategoryAmbient (source):




    This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays while the Music app is playing. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).







    share|improve this answer
























    • I tried this did not work for me but I am also not trying to play back music. The only place I am getting this message is when AdMod tries to display an ad which means I am getting it a lot. If the above is the correct answer it should shutdown this message in all cases since all other attempts to ask this question have been labeled duplicates and referred to this answer.

      – Sojourner9
      Oct 24 '18 at 21:42











    • @Sojourner9 for what I've read on the Apple Developer forums it seems to be a problem specific to iOS 12. Since the message comes from iOS, haven't found a way to silence it. That's why I mentioned that perhaps Apple will fix this soon. Maybe AdMob is trying to play a sound or a video so it's triggering this message? Are you using iOS 12 too?

      – Victor Sanchez
      Oct 26 '18 at 3:24














    16





    +50







    16





    +50



    16




    +50





    The message Unknown selected data source for Port Speaker seems to be a problem with iOS 12. Apparently it's some warning that appears even if the code is working. Perhaps Apple will fix this soon, so maybe for now you can ignore this warning and once they find a solution you will be able to silence it.



    Source: AVAudioSession errors in iOS 12



    As for the background music playing on silent mode, it's because of the AVAudioSessionCategory you selected. According to AVAudioSessionCategoryPlayback documentation (source):




    When using this category, your app audio continues with the Silent switch set to silent or when the screen locks.




    Depending on the style of your app, maybe you could use AVAudioSessionCategorySoloAmbient (source):




    Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).




    Or maybe AVAudioSessionCategoryAmbient (source):




    This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays while the Music app is playing. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).







    share|improve this answer













    The message Unknown selected data source for Port Speaker seems to be a problem with iOS 12. Apparently it's some warning that appears even if the code is working. Perhaps Apple will fix this soon, so maybe for now you can ignore this warning and once they find a solution you will be able to silence it.



    Source: AVAudioSession errors in iOS 12



    As for the background music playing on silent mode, it's because of the AVAudioSessionCategory you selected. According to AVAudioSessionCategoryPlayback documentation (source):




    When using this category, your app audio continues with the Silent switch set to silent or when the screen locks.




    Depending on the style of your app, maybe you could use AVAudioSessionCategorySoloAmbient (source):




    Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).




    Or maybe AVAudioSessionCategoryAmbient (source):




    This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays while the Music app is playing. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).








    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 19 '18 at 5:28









    Victor SanchezVictor Sanchez

    461311




    461311













    • I tried this did not work for me but I am also not trying to play back music. The only place I am getting this message is when AdMod tries to display an ad which means I am getting it a lot. If the above is the correct answer it should shutdown this message in all cases since all other attempts to ask this question have been labeled duplicates and referred to this answer.

      – Sojourner9
      Oct 24 '18 at 21:42











    • @Sojourner9 for what I've read on the Apple Developer forums it seems to be a problem specific to iOS 12. Since the message comes from iOS, haven't found a way to silence it. That's why I mentioned that perhaps Apple will fix this soon. Maybe AdMob is trying to play a sound or a video so it's triggering this message? Are you using iOS 12 too?

      – Victor Sanchez
      Oct 26 '18 at 3:24



















    • I tried this did not work for me but I am also not trying to play back music. The only place I am getting this message is when AdMod tries to display an ad which means I am getting it a lot. If the above is the correct answer it should shutdown this message in all cases since all other attempts to ask this question have been labeled duplicates and referred to this answer.

      – Sojourner9
      Oct 24 '18 at 21:42











    • @Sojourner9 for what I've read on the Apple Developer forums it seems to be a problem specific to iOS 12. Since the message comes from iOS, haven't found a way to silence it. That's why I mentioned that perhaps Apple will fix this soon. Maybe AdMob is trying to play a sound or a video so it's triggering this message? Are you using iOS 12 too?

      – Victor Sanchez
      Oct 26 '18 at 3:24

















    I tried this did not work for me but I am also not trying to play back music. The only place I am getting this message is when AdMod tries to display an ad which means I am getting it a lot. If the above is the correct answer it should shutdown this message in all cases since all other attempts to ask this question have been labeled duplicates and referred to this answer.

    – Sojourner9
    Oct 24 '18 at 21:42





    I tried this did not work for me but I am also not trying to play back music. The only place I am getting this message is when AdMod tries to display an ad which means I am getting it a lot. If the above is the correct answer it should shutdown this message in all cases since all other attempts to ask this question have been labeled duplicates and referred to this answer.

    – Sojourner9
    Oct 24 '18 at 21:42













    @Sojourner9 for what I've read on the Apple Developer forums it seems to be a problem specific to iOS 12. Since the message comes from iOS, haven't found a way to silence it. That's why I mentioned that perhaps Apple will fix this soon. Maybe AdMob is trying to play a sound or a video so it's triggering this message? Are you using iOS 12 too?

    – Victor Sanchez
    Oct 26 '18 at 3:24





    @Sojourner9 for what I've read on the Apple Developer forums it seems to be a problem specific to iOS 12. Since the message comes from iOS, haven't found a way to silence it. That's why I mentioned that perhaps Apple will fix this soon. Maybe AdMob is trying to play a sound or a video so it's triggering this message? Are you using iOS 12 too?

    – Victor Sanchez
    Oct 26 '18 at 3:24













    2














    From Swift 4.2, I originally had it set up like this:



    try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: )


    I didn't actually need recording capabilities, so I changed it to



    try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: )


    This removed the error (and was the only thing I could do to get the error gone). However, if you need recording capabilities as well, obviously this won't work.






    share|improve this answer




























      2














      From Swift 4.2, I originally had it set up like this:



      try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: )


      I didn't actually need recording capabilities, so I changed it to



      try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: )


      This removed the error (and was the only thing I could do to get the error gone). However, if you need recording capabilities as well, obviously this won't work.






      share|improve this answer


























        2












        2








        2







        From Swift 4.2, I originally had it set up like this:



        try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: )


        I didn't actually need recording capabilities, so I changed it to



        try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: )


        This removed the error (and was the only thing I could do to get the error gone). However, if you need recording capabilities as well, obviously this won't work.






        share|improve this answer













        From Swift 4.2, I originally had it set up like this:



        try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: )


        I didn't actually need recording capabilities, so I changed it to



        try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: )


        This removed the error (and was the only thing I could do to get the error gone). However, if you need recording capabilities as well, obviously this won't work.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 13 at 0:58









        Adam S.Adam S.

        73210




        73210






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52626252%2funknown-selected-data-source-for-port-speaker-type-speaker%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'