Download & Extend

1pixelout should play one MP3 at a time, and not simultaneously

Project:SWF Tools
Version:6.x-2.5
Component:SWF Tools
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Issue tags:mp3, pause, simultaneous, swf tools

Issue Summary

Hi,

I have a content type called "Audio List", which is just a bunch of CCK FileFields. I have installed SWFTools and 1pixelout audio player and assigned the MP3 files to be handled by it. In Content Types >> Edit Audio List >> Display Fields I have set it to display as "SWFTools - no download links". Then I uploaded a few MP3s. The first problem is that it does not display the Caption text entered for each of the files. But the biggest problem is that if I start playing one of the audio files and then click the "play" of another file, the previous player does not collapse and stop playing, but continues to play simultaneously. Naturally, a user of SWFTools would expect the same behavior as the Audio-Player plugin in Wordpress: if you're already playing first song and then suddenly click the play button of another file, then the first player should collapse and stop playing, so that the second song begins playing.

If I overlooked one of the settings, please treat this is as a support request and please tell me how to do it right.
If not, then I guess this is a bug report which needs to be corrected.

Thank you very much for a great module!

Comments

#1

Seconding this problem. The IDs for each audio player are unique, so some section that checks for redundant IDs isn't working, I'm assuming. Any ideas?

#2

Okay, so it actually seems that when the ap_stopall(playerID) function inside onepixelout.js is called, the argument playerID isn't being read correctly and comes up as undefined. any ideas?

#3

Also having this issue. Any ideas where to start debugging to help find a fix?

#4

At the time of this post, an example of this problem can be seen on my site at:

http://tonewells.com/audio

This is a view page set up to display all audio nodes, utilizing the 1 pixel out mp3 player... but as everyone else mentioned it would be much more pleasant to have one collapse as the other opens.

Many thanks to anyone working on this!

#5

Would like to see this solved as well! Wish I knew enough code to help out.

Another function I could see working along with this fix is an autostart first ID on page (optional of course), let me know if I should create another node for this, I probably will anyway.

#6

#7

HEY GUYS HEY GUYS I FIGURED IT OUTT

So here's the reason why it wasn't working: we were all probably downloading the new onepixelout 2.0 beta from here. The developer, Martin Laine, changed the function called upon pressing play from one called 'ap_stopall' to something else. I downloaded the new javascript and futzed around with it and came up with this:

var AudioPlayer = function () {
        var activePlayerID;
           
        function getPlayer(playerID) {
                var playerObjID = $("[id*=" + playerID + "]").attr('id');
                return document.getElementById(playerObjID);
        }  
           
        return {
                getPlayer: function (playerID) {
                        return getPlayer(playerID);
                }, 
                   
                activate: function (playerID) {
                        if (activePlayerID && activePlayerID != playerID) {

                                getPlayer(activePlayerID).close();
                        }  
                           
                        activePlayerID = playerID;
                }, 
                   
                close: function (playerID) {
                        getPlayer(playerID).close();
                        if (playerID == activePlayerID) {
                                activePlayerID = null;
                        }  
                }, 
        }  
}();

This needs to be invoked by drupal_add_js in function onepixelout_push_js at the bottom of modules/swftools/onepixelout/onepixelout.module. Also, you need jQuery, but if you want you could modify the var playerObjID = $("[id*=" + playerID + "]").attr('id'); to work in pure Javascript.

#8

sorry, don't know any other coding besides html/css could you explain what to do with your fix?

thanks in advance

#9

Right.

1) Make sure your site has jQuery enabled. I use jQuery Update.
2) Create a javascript file in sites/all/modules/swftools/onepixelout, and call it anything -- say, onepixelout_new.js.
3) Copy-paste the above javascript code into this file.
4) Edit sites/all/modules/swftools/onepixelout/onepixelout.module. At line 168, in function onepixelout_push_js(), edit the file called by drupal_add_js to 'onepixelout_new.js' so that it looks like:
drupal_add_js(drupal_get_path('module', 'onepixelout') .'/onepixelout_new.js', 'module', 'header');

Now it should work!

#10

I actually have the 1.2.3 version of the player.swf so I don't believe that this solution would work for me.

#11

Not sure if you all want to do this, but the way I fixed this issue was to use a different embedding method in the SWFTools settings. This is how I did it:

  • Install swftools as normal
  • Go to the modules page of your site and enable the SWFObject2 module in the SWFTools section of that page
  • Go to the SWFTools status report at http://[yoursite]/admin/reports/swftools
  • If you have any warnings, fix them - you will probably need to download the SWFObject2 JavaScript file. Follow the link on the status report page to download the ZIP file
  • Unzip the downloaded ZIP file into a temporary directory
  • Create the folder sites/all/modules/swftools/shared/swfobject2 in your Drupal directory
  • Copy the swfobject.js file from the temporary directory to the sites/all/modules/swftools/shared/swfobject2 folder
  • Go back to your SWFTools Status Report and verify that SWFObject2 is green and says OK
  • Go to the SWFTools Embedding settings at http://[yoursite]/admin/settings/swftools/embed
  • Switch the embedding method to SWFObject2 - JavaScript and check the box Add JavaScript to all pages

    Once I performed those actions then my the currently playing 1pixelout player would pause if I started playing another clip on the same page.

    Hope this helps,
    Flux.

  • #12

    worked great! thanks guys!

    however, I have a few players listed in a view and I want just the first one to autostart but when I enable autostart they still all play..

    any ideas?

    thanks in advance

    #13

    Using swftools 6.x-2.5, swfobject_2_2, 1pixelout audio-player.2.0.2, all config'd per docs (unless I missed something), with multiple players on a page, each with unique ID's: Still the players will play simultaneously.

    Stumped: What should I do to fix this?

    #14

    I'm back on with SWF Tools. When I reset everything locally I also had this problem. It looks like somewhere along the lines I changed some of the css tagging that goes around flash content, and this was confusing the script that detects the players. The code also worked for direct embedding only, not with swfobject.

    I'm working on a new release on branch DRUPAL-6--3 that should fix this. Because of that for now I've not gone back to the 6.x-2.x branch for now.

    There is a new audio player, and I've not yet checked it out in detail to see what needs to be changed to support it, but I will do that as the compact player is a popular choice for podcasts and similar.

    #15

    Hi,

    Check out this post. http://drupal.org/node/708724. I am having the same issue but with JW FLV MEdia player. I tried what djflux says in comment 11 but no luck. Do the mp3s have to reside locally or can they be an external address? I am using a CCK field to add the path but it just shows up as a link when published.

    I have posted some interesting links which could provide a solution for this issue so you can have a look and perhaps we can come up with a solution as it seems many are facing this issue in drupal.

    Thanks

    #16

    Status:active» needs review

    This is now fixed on branch DRUPAL-6--3 and it should work ok on swfobject and direct embedding.

    #17

    I just gave the 3x-dev a test-ride and can confirm that each player is playing 1 song at a time. So that's fixed.

    #18

    Behavior is consistent across browsers with SWF Object embedding, but doesn't seem to work in all cases for direct embedding.

    I've been implementing the equivalent code for the new WordPress audio player and have got the same. For now I'm going to leave this feature as working properly only with SWF Object embedding as it's too frustrating!

    Under SWF Object it's good, and the new player has autoclose behavior, but also synchronised volume which is neat!

    #19

    Can anyone tell us if there is an eta on the 6.3 update?

    or is it possible to download the dev version somewhere?

    Thanks.

    #20

    Probably another couple of weeks and it'll be there. You can get the latest development stuff from CVS branch DRUPAL-6--3, or use the snapshot package.

    #21

    Now working properly in all browsers, and with both direct embedding and swfobject2 embedding!

    #22

    Awesome :-)

    Is the fix with swfobject 2 fixed in the cvs already?

    Im using this method of embedding, so I would love to give it a test drive.

    I did try Revision 1.3.2.2 but it doesnt fix it yet with swfobject 2.

    #23

    It should be, but sometimes there's a delay between the commit I make, and the package generating.

    Also, the behavior is currently fixed in the new WordPress audio player, but I can bring back the fix to OnePixelOut shortly as the code will basically be the same. But I'm kind of guessing people will move to the new player since this is supercedes OnePixelOut v1.

    Will do that shortly and update the thread accordingly.

    #24

    So just to be sure, 1.3.2.2.2.1 is the one you are talking about then, right?

    Because that one says "file removed"

    #25

    The 6..x-3.x development package is at http://drupal.org/node/586002. The version number on swf.module for the commit I just made is 1.20.2.16.2.31. Provided you have that, or higher, you should have working auto-stop behaviors for OnePixelOut, WordPress audio, and LongTail (Wijering) 4.

    Note - at the moment the auto-stop code only stops players of the same "type". I'm thinking about whether it would be needed to have, e.g. a WordPress player also stop Longtail players. Would anyone run both?!

    I've just re-commited the code as there were (yet more) issues with getting the support working in all browsers, and under both direct and swfobject embedding.

    BUT, I think it's there now. The behavior looks good across IE, FF and Chrome under both embedding methods. While there are clearly more browsers this is looking pretty good, so I'd appreciate any reports of whether it works / fails under other combinations.

    The key issue is in picking up the right object in the DOM as different browsers like it different ways...

    #26

    Thanks for that.

    I tried to update to this dev version, but after running php.update in drupal, I get this error:

    Fatal error: Call to undefined function swftools_get_player_path() in ..../sites/all/modules/swftools/wijering4/wijering4.module on line 30

    Perhaps the fault is on my end, but I thought I would mention it, in case its not.

    #27

    You need to download and replace the whole SWF Tools package, not just component modules. All player modules are now renamed to swftools_.module. So wijering4.module no longer exists, it is swftools_wijering4.module.

    I've not updated the docs yet as the module is under development. Note that your existing content will work fine with the new SWF Tools.

    I've raised a new thread to start describing the process, in preparation for an offical docs page - see #745050: Create upgrade instructions for 6.x-2.x to 6.x-3.x.

    #28

    Hi Stuart,

    Thanks for that.

    I did indeed install over the previous version, instead of deleting, so that was the problem.

    I have now successfully installed the new dev version, but the one pixels still dont auto close when a new one is started. (both on safari and firefox)

    I also noticed that swfobject2 is the only possible way of embedding in the dev package, perhaps thats the problem?

    All the other embedding options seem to be gone.

    #29

    Sounds like something isn't working right - you should always have direct embedding available as that is built in to SWF Tools.

    Try running update.php to check all the updates have gone through, and try resetting the embedding page to its defaults to make sure that it is ok.

    Also, try clearing your site cache to make sure that there are no old filters being picked up.

    Lastly, try clearing your browser cache. The underlying scripts have been changed quite a bit so an old cached version will probably not work.

    On my test rig (a desktop, and a laptop) it's working for me under IE, FF and Chrome. I'll try Safari tonight.

    Lastly, do you have the site on a public facing page? That way I can take a look and see if the code looks right / test if it works (or not) for me.

    #30

    Hi,

    Sorry for not being more clear.

    I do have both direct embedding and swfobject2 available, just not swfobject. (Which I thought was the necessary method for now, since you said swfobject2 was a bit messy?)

    I have now tried both direct and sfwobject2, and both methods fail as far as auto-closing players go.

    I already did everything mentioned above, even rebuild menus, but nothing changes. (safari & FF)

    Take a look yourself over here: http://markusproductions.com/listen

    #31

    It's probably me breaking the code again! I'll check tonight. The page looks right, and the script looks right, but it didn't work when I opened the page, so it seems that I broke it again...

    I know it CAN work, but I've given the JavaScript a major overhaul and seems it's gone off again - sorry!

    #32

    One thing to check - on the embedding settings page check that the swliveconnect option is checked. Your page source is showing swliveconnect="false" which if I remember rightly prevents JavaScript access. Turning the option on might cure it!

    #33

    Actually tried that too, but I turned it back off when it didn't work.

    I'll leave it on now.

    Still not working though, with both swfobject2 and direct.

    are there any other nessesary settings I could have overlooked, or is the code broken you think?

    Thanks for your help so far!

    #34

    OK. I've done lots more testing and there was a problem with the common JavaScript function that SWF Tools uses to "find" the object on the page and it failed with FF + swfobject embedding. It was working ok with IE and Chrome though.

    I've spent some more time trying to fix it, and have just committed a new version of the script.

    Locally I've tested using direct embedding and swfobject embedding, in IE, Firefox and Chrome, and for each of those I've tested OnePixelOut, Wijering4 and WordPress audio, and it seems to be working...

    But then I thought that last time too...

    If you don't mind could you give it a go. Not sure when the package will next generate, but a package containing swftools.js script version 1.1.2.3 or higher means you have it.

    In terms of settings, it's not the swliveconnect setting that matters, but the allowscriptaccess one. You must ensure that allowscriptaccess is not set to never as this will block the JavaScript from interacting with the players.

    #35

    Hi Stuart.

    I'm gone for the weekend but I'll make sure to give it a test run 1st thing Monday.

    I have the script setting set to allow scripts on the Sam e domain I believe.

    Where can I download the package u just did? Or did u update the last one?

    I'll give u some feedback asap on Monday!

    Have a good weekend.

    #36

    The snapshot package will update itself, and should be good by Monday as it is re-created every twelve others.

    I'm going to clear all the browser caches locally to double check it really is working now.

    But x players by y embedding methods by z browsers = lots of testing :-(

    #37

    Hi Stuart,

    Sorry I was a bit late.

    anyhow, I updated following all the steps, and no errors, so that was good.

    However, FF & Safari, still no go.

    Check yourself if you want.

    Players still don't autoclose.

    #38

    Arrrggggh! I am sure this was working for me locally. I can see from your page that the script is starting to run as the onepixelout players have been tagged with the swftools-onepixelout-processed class which is needed to identify the players.

    To test this further you'll need to add some diagnostics to the onepixelout script for me. You can use alert() or console.log() as you prefer.

    In the file /sites/all/modules/swftools/onepixelout/swftools_onepixelout.js try the following:

    /**
    * Callback from OnePixelOut to stop all players when a player is stopped.
    */
    function ap_stopAll(playerID) {
      swftools.onepixelout.closeAll(playerID);
    }

    /**
    * Define OnePixelOut functions here.
    */
    swftools.onepixelout = function() {
      var instances = [];
      return {
        pushInstance: function(playerID) {
          instances.push(playerID);
        },
        closeAll: function(playerID) {
          for(var i = 0; i < instances.length; i++) {
            player = swftools.getObject('swf-' + instances[i]);
            if(instances[i] != playerID) {
              player.SetVariable('closePlayer', 1);
            }
            else {
              player.SetVariable('closePlayer', 0);
            }
          }
        },
      }
    }();

    becomes

    /**
    * Callback from OnePixelOut to stop all players when a player is stopped.
    */
    function ap_stopAll(playerID) {
      // Tell me which player is starting
      alert('Onepixelout is starting ' + playerID);
      swftools.onepixelout.closeAll(playerID);
    }

    /**
    * Define OnePixelOut functions here.
    */
    swftools.onepixelout = function() {
      var instances = [];
      return {
        pushInstance: function(playerID) {
          // Tell me that we pushed this player
          alert('Pushing player ' + playerID);
          instances.push(playerID);
        },
        closeAll: function(playerID) {
          // Tell me that I got here
          alert('Doing swftools.onepixelout.closeAll');
          for(var i = 0; i < instances.length; i++) {
            player = swftools.getObject('swf-' + instances[i]);
            // Tell me if we got a player
            alert(typeof player);
            if(instances[i] != playerID) {
              // Let this player close
              alert('Closing player ' + instances[i]);
              player.SetVariable('closePlayer', 1);
            }
            else {
              // Keep this player open
              alert('Keep open player ' + instances[i]);
              player.SetVariable('closePlayer', 0);
            }
          }
        },
      }
    }();

    Now when you load the page you'll get a run of alerts, or console messages, telling us what is going on.

    We should see players being pushed, so we know we collected all their ids, then when you activate a player we call ap_StopAll. This should be followed by confirmation that we did indeed get a player (type of returns object or function, depending on the browser), and then confirmation of what action is being attempted on each player (let it close, or keep it open).

    Could you try this, and could you post what sequence of messages you get. I can then simulate locally tonight and confirm I get the same series.

    The only thing I can think of is that some other script on the page is interfering, but I don't see what that would be, or why.

    #39

    Updated the script for you.

    Not sure how to do the console thing though, can u be a bit more specific?

    I've never used that b4 :-)

    Is it the logging module in drupal core?

    #40

    Small update,

    I cleaned all caches, and now ff gives error messages for all players on the page.

    A window pops up saying: The page at http://markusproductions.com says:
    Pushing player 12693520911

    I have to click on ok, and then get the same msg for the next player.

    #41

    Don't worry about console.log. What you are seeing are not error messages, but the output of the alert messages the code sample has put in place.

    Can you post the entire sequence of messages that you see, from opening the page, and then when you start a player.

    For example, on my test rig, with three OnePixelOut players I see:

    • Pushing player 12693674311
    • Pushing player 12693674312
    • Pushing player 12693674313
    • Onepixelout is starting 12693674311
    • Doing swftools.onepixelout.closeAll
    • function
    • Keep open player 12693674311
    • function
    • Closing player 12693674312
    • function
    • Closing player 12693674313

    What that tells me is that all three players got pushed, I started a player, the proper handling functions were called, that the code returned player objects that were identified as a function (which is what FireFox does), and that we then kept the proper player open, and closed the others.

    This was me testing on the latest version of SWF Tools 6.x-3.x, with SWFObject2 embedding.

    What we're looking for are things like: not all players being pushed, players with the same ID, the handler functions not being called, or players being returned as 'undefined' meaning the script didn't identify the player object properly.

    If you could post one dump of what you see that would be great!

    Thanks

    #42

    I went to your page and see that you still have the modified onepixelout.js in place, so I could see that you only see the players being pushed - you never see "Onepixelout is starting 12693674311", so a call to ap_stopAll() is never being made. And that means the auto-stop doesn't work.

    I don't know why this should be failing. Maybe another script is conflicting somehow, but I'm not sure how/why.

    Can anyone else either (a) confirm that the auto-stop is working, or (b) what the problem might be.

    edit--
    can you try setting allowscriptaccess to always on your embedding page, and see if that gets it to work. I have tried configuring players on my page in exactly the same way as you, and they work, and I've even downloaded and used your aggregated JavaScript file, and it works for me locally!
    /edit--

    #43

    Got it!

    You have installed the new WordPress audio player, not the original OnePixelOut player.

    I should have recognised the player from the volume icon which is different. I've been messing around with a copy of your webpage, and as a final last resort decided to replace your player file with mine, and the copy alerted me that the file sizes were different.

    If you want OnePixelOut you need http://downloads.wordpress.org/plugin/audio-player.1.2.3.zip. Replace your current /sites/all/libraries/audio-player/audio-player/player.swf with the one in that zip and you should be fine. When I make the replacement locally it starts working.

    Or if you want to use the newer WordPress audio player then you need to drop player.swf one level higher in the libraries (so its in sites/all/libraries/audio-player/player.swf. Then use the new WordPress audio module in place of OnePixelOut.

    Phew.

    Now, back to what I had planned to work on :-)

    Oh, and replace onepixelout.js with the original version to get rid of all those debug messages!

    #44

    Works perfect now!

    Thanks so much for your help, its much appreciated!

    Maybe you should mention something in the future documentation, because I did download the 1pixel out player from the link that is given by the previous version of swf tools.

    If I can test something in the future to help you out, please ask!

    Thanks again.

    Cheers,

    #45

    The problem I am experiencing happens in version 6.x-2.5 and 6.x-3.0-beta4. When using the onepixelout player there appears to be an issue when multiple players are displayed in a view. In my case I am displaying three audio players in a block view and paginating the results when more that three audio players exist. When you start the players of the first page of the block view, onepixelout players start and stop as they should. You start one player and then when you start another, the previous stops.

    The issue I am having arises when you go to the second page of a paginated block view. At that point a previous player is not closed when you start another. In the onepixelout.js file I seem to have tracked the issue to lines 8 - 17:

    onepixelout_initialized = 0;

    // Call back when a player is started - it uses the flashvar playerID of the player that is starting as its parameter
    function ap_stopAll(playerID) {
     
      // If this is the first time we clicked a player then get the object and player ids
      if (!onepixelout_initialized) {
        onepixelout_getPlayers();
        onepixelout_initialized = 1;
      }

    The problem with this code seems to be that initially when the block is loaded it has three players. When you start the first player, onepixelout_getPlayers() is run which gets the id's of all of the players on the page (currently 3 players) and then the counter onpixelout_initialized is set to 1. When you go to the second page of the paginated block view and start a player, onpixelout_initialized is equal to 1 so _getPlayers() does not run again thus the newly added player id's of the next page of players is unknown to the ap_stopAll function which breaks the stopping of previous players. I was able to hack the script so that onepixelout_getPlayers() runs everytime a player is clicked which solves the problem but doesn't seem like the proper solution.

    // Call back when a player is started - it uses the flashvar playerID of the player that is starting as its parameter

    function ap_stopAll(playerID) {
    // Moved getPlayers function out of initialized conditional to run on every click so when new players are added through pagination //the script is made aware of their id's
    onepixelout_getPlayers();

    It would seem that drupal.behaviors would be the correct way to solve this issue and after looking into the swftools 6.x-3 swftools_onepixelout.js, the javascript has been written to utilize behaviors however, After experimenting with this version of swftools I get the error:

    "player is null" in the firebug console when you try and play a onepixelout player on subsequent pages within a paginated block view. This causes the closing of previous players to fail as well.

    This error seems to occur in: swftools_onepixelout.js within the closeAll function.

    closeAll: function(playerID) {
          for(var i = 0; i < instances.length; i++) {
            player = swftools.getObject('swf-' + instances[i]);
    alert(player);
            if(instances[i] != playerID) {
              player.SetVariable('closePlayer', 1);
            }
            else {
              player.SetVariable('closePlayer', 0);
            }
          }
        },

    I haven't been able to track down exactly what is causing the problem in this script but it seems to have something to do with getObject failing in the paginated block scenario.

    I have attached a screenshot of the block to demonstrate the issue.

    AttachmentSize
    player.jpg 10.81 KB

    #46

    So I think i tracked down the issue within swftools_onepixelout.js within the swftools 6.x-3.0beta4 module that was causing the issue in my previous comment. The issue was occurring because the instances array was not being reset when drupal behaviors ran. Because of this, ids of AJAX loaded content are added into the array but the previous id's of objects that are no longer displayed on the page are not removed. In my example in my paginated block, there should only be three id's in that array in any given time as my block only displays three items. With the way the js is currently coded the array will continue to fill with items as you click on more and more paginated links. Because of this array setup :

    player = swftools.getObject('swf-' + instances[i]);
    is fed id's of elements that don't exist on the page. At this point, the getObject function in swftools.js fails swftoolsObject = document.getElementById(objectID); because the id that is passed to getElementById doesn't exist on the page. The below solution seemed to fix the problem:

    /**
    * Define OnePixelOut functions here.
    */
    swftools.onepixelout = function() {
      var instances = [];
      return {
        // Setup the function to clear out the instances array when behaviors are re-attached
        clearInstances: function() {
        instances.length = 0;
        },
        pushInstance: function(playerID) {
          instances.push(playerID);
        },
        closeAll: function(playerID) {
          for(var i = 0; i < instances.length; i++) {
            player = swftools.getObject('swf-' + instances[i]);
            if(instances[i] != playerID) {
              player.SetVariable('closePlayer', 1);
            }
            else {
              player.SetVariable('closePlayer', 0);
            }
          }
        },
      }
    }();

    Drupal.behaviors.swftools_onepixelout = function (context) {

    //Clear out our array here so we have a clean slate
      swftools.onepixelout.clearInstances();

      $('.swftools-onepixelout:not(.swftools-onepixelout-processed)', context).addClass('swftools-onepixelout-processed').each(function () {
        swftools.onepixelout.pushInstance($(this).attr('id').substring(13));
      });
    }

    I added a clearInstances function to swftools.onepixelout and I call the function in the drupal behavior first before any other processing takes place to clear out the old array entries so there is a clean slate to pushInstances onto.

    This solution seems to make the onepixelout javascript AJAX friendly :)

    #47

    theres a compatibility issue with php 5.3 in the stable release, the patch in this thread http://drupal.org/node/589326 fixed this issue for me (-> stop the other players when starting another)

    nobody click here