Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:07:10+00:00 2026-05-23T18:07:10+00:00

Hopefully I can articulate this problem well. I’m working on a simple audio player

  • 0

Hopefully I can articulate this problem well. I’m working on a simple audio player in Titanium Desktop. The primary code I’m focused on right now is the following:

function pickMusicFolder (){
    var win = Titanium.UI.getCurrentWindow();

    win.openFolderChooserDialog(function(folderResponse) {
        var file = Titanium.Filesystem.getFile(folderResponse[0]);
        var listing = file.getDirectoryListing();
        for (var i = 0; i < listing.length; i++) {
            if (listing[i].isDirectory()) {
                // if the listing is a directory, skip over it
                $('#main').append('DIRECTORY: ' + listing[i].nativePath() +
                    '<br />');
                // continue;
            }
            else {
                // otherwise, print the filename of the file to the #main content window
                var songOnList = listing[i].nativePath();
                var songURL = songOnList.replace(/\\/g,"/");
                $('#main ul').append('<li><a href="javascript:playSong(\'' + songURL + '\')">' + songURL + '</a></li>');
            }
        }
    });
};

function playSong(songURL){
    var currentSong = Titanium.Media.createSound(songURL);
    currentSong.play();

    this.stopPlayback = stopPlayback;

    function stopPlayback(currentSong){
        currentSong.stop();
    }
}

And then related HTML:

<input type="image" src="img/player_stop.png" name="stopPlayback" onClick="playSong.stopPlayback(songURL)" />
<input type="image" src="img/folder_add.png" name="pickMusicFolder" onClick="pickMusicFolder()" />

Now, both pickMusicFolder and playSong itself work properly. However, stopPlayback isn’t working, I’m having a really hard time grasping how to deal with different functions for playing and stopping audio, since the code that’s generating the clickable links is completely compartmentalized within the pickMusicFolder function, while the code for stopping playback is only attached to the one separate interface button.

I simply need access to the songURL variable between multiple functions in order to be able to perform operations on one solitary song while it’s playing (or not). I’m avoiding resorting to global variables, as I find that to be sort of a cop out.

Anyone have any ideas? Any tips are much appreciated! (Oh, and please ignore my ugly code; was trying a bunch of hack-y solutions before posting.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:07:11+00:00Added an answer on May 23, 2026 at 6:07 pm

    Very quickly solution is to store currentSong as property of function playSong:

    function playSong(songURL){
      var currentSong = Titanium.Media.createSound(songURL);
      playSong.currentSong = currentSong; // store curernt playing song as property of function
      currentSong.play();
    }
    
    playSong.stopPlayback = function() {
      if (playSong.currentSong) {
        playSong.currentSong.stop();
        delete playSong.currentSong;
      }
    };
    

    when song will be stopped just remove this property that would mean no song are playing now

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is hard to explain but hopefully I can articulate my problem well enough.
Hopefully I can articulate this well: I'm porting an application I made years ago
Hopefully I can explain this well enough, but please let me know if more
Hopefully someone can help me with this problem. I'm starting to work with Drupal
this is my first question here so I hope I can articulate it well
Hopefully I can explain this well and hopefully I'm thinking the right way :)
I'm not really sure why this isn't working, hopefully you can help me find
Hopefully I can articulate my question well enough to get some clear and usable
Hopefully someone can help me debug this problem as EXC_BAD_ACCESS is the only error
Hopefully I can explain this well. Assume the following: @interface ClassA : NSObject {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.