home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / components / sbPlaylistReaderListener.js < prev    next >
Text File  |  2012-06-08  |  6KB  |  202 lines

  1. /*
  2.  //
  3. // BEGIN SONGBIRD GPL
  4. //
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright(c) 2005-2008 POTI, Inc.
  8. // http://songbirdnest.com
  9. //
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the "GPL").
  12. //
  13. // Software distributed under the License is distributed
  14. // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
  15. // express or implied. See the GPL for the specific language
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc.,
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. //
  23. // END SONGBIRD GPL
  24. //
  25.  */
  26.  
  27. //
  28. // sbIPlaylistReaderListener Object
  29. //
  30. const Cc = Components.classes;
  31. const Ci = Components.interfaces;
  32. const Cr = Components.results;
  33.  
  34. const SONGBIRD_PLAYLISTREADERLISTENER_CONTRACTID = "@songbirdnest.com/Songbird/PlaylistReaderListener;1";
  35. const SONGBIRD_PLAYLISTREADERLISTENER_CLASSNAME = "Songbird Playlist Reader Listener"
  36. const SONGBIRD_PLAYLISTREADERLISTENER_IID = Components.interfaces.sbIPlaylistReaderListener;
  37. const SONGBIRD_PLAYLISTREADERLISTENER_CID = Components.ID("{b4fac7ab-7d23-47c5-98e0-7e59266e2a28}");
  38.  
  39. function CPlaylistReaderListener()
  40. {
  41. }
  42.  
  43. CPlaylistReaderListener.prototype.constructor = CPlaylistReaderListener;
  44.  
  45. CPlaylistReaderListener.prototype =
  46. {
  47.   originalURI: null,
  48.   destinationURI: null,
  49.   addDistinctOnly: false,
  50.   playWhenLoaded: false,
  51.   mediaMimetypesOnly: false,
  52.   observer: null,
  53.   state: "",
  54.  
  55.   onLocationChange: function(aWebProgress, aRequest, aLocation)
  56.   {
  57.   },
  58.  
  59.   onProgressChange: function(aWebProgress, aRequest, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress)
  60.   {
  61.   },
  62.  
  63.   onSecurityChange: function(aWebProgress, aRequest, aStateFlags)
  64.   {
  65.   },
  66.  
  67.   onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
  68.   {
  69.     if (aStateFlags & 16 /*this.STATE_STOP*/)
  70.     {
  71.       // mark ourself as finished so the PlaylistReaderManager can remove us.
  72.       this.state = "STATE_STOP";
  73.  
  74.       var playlistReaderMngr = Cc["@songbirdnest.com/Songbird/PlaylistReaderManager;1"]
  75.                                  .getService(Ci.sbIPlaylistReaderManager);
  76.       var mm = Cc["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
  77.                  .getService(Ci.sbIMediacoreManager);
  78.  
  79.       var strContentType = "";
  80.       var aChannel = aRequest.QueryInterface(Components.interfaces.nsIChannel);
  81.       if (aChannel)
  82.       {
  83.         try
  84.         {
  85.           strContentType = aChannel.contentType;
  86.         }
  87.         catch (err) {
  88.           Components.utils.reportError(err);
  89.         } // Grrrr.
  90.       }
  91.       playlistReaderMngr.originalURI = this.originalURI;
  92.       try {
  93.         playlistReaderMngr.loadPlaylist(this.destinationURI,
  94.                                         this.mediaList, strContentType,
  95.                                         this.addDistinctOnly,
  96.                                         null);
  97.         if (this.playWhenLoaded)
  98.         {
  99.           var view = this.mediaList.createView();
  100.           mm.sequencer.playView(view, 0);
  101.         }
  102.         if (this.observer)
  103.         {
  104.           this.observer.observe(this.mediaList, "success", "");
  105.         }
  106.       }
  107.       catch(e)
  108.       {
  109.         if (this.observer)
  110.           this.observer.observe(null, "error: could not create playlist", "");
  111.         Components.utils.reportError(e);
  112.       }
  113.       finally
  114.       {
  115.         playlistReaderMngr.originalURI = null;
  116.       }
  117.     }
  118.   },
  119.  
  120.   onStatusChange: function(aWebProgress, aRequest, aStateFlags, strStateMessage)
  121.   {
  122.   },
  123.  
  124.   QueryInterface: function(aIID)
  125.   {
  126.     if (!aIID.equals(Components.interfaces.sbIPlaylistReaderListener) &&
  127.         !aIID.equals(Components.interfaces.nsIWebProgressListener) &&
  128.         !aIID.equals(Components.interfaces.nsISupportsWeakReference) &&
  129.         !aIID.equals(Components.interfaces.nsISupports))
  130.     {
  131.       throw Components.results.NS_ERROR_NO_INTERFACE;
  132.     }
  133.  
  134.     return this;
  135.   }
  136. };
  137.  
  138. /**
  139.  * \class sbPlaylistReaderListenerModule
  140.  * \brief
  141.  */
  142. var sbPlaylistReaderListenerModule =
  143. {
  144.   registerSelf: function(compMgr, fileSpec, location, type)
  145.   {
  146.       compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  147.       compMgr.registerFactoryLocation(SONGBIRD_PLAYLISTREADERLISTENER_CID,
  148.                                       SONGBIRD_PLAYLISTREADERLISTENER_CLASSNAME,
  149.                                       SONGBIRD_PLAYLISTREADERLISTENER_CONTRACTID,
  150.                                       fileSpec,
  151.                                       location,
  152.                                       type);
  153.   },
  154.  
  155.   getClassObject: function(compMgr, cid, iid)
  156.   {
  157.       if (!cid.equals(SONGBIRD_PLAYLISTREADERLISTENER_CID))
  158.           throw Components.results.NS_ERROR_NO_INTERFACE;
  159.  
  160.       if (!iid.equals(Components.interfaces.nsIFactory))
  161.           throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  162.  
  163.       return sbPlaylistReaderListenerFactory;
  164.   },
  165.  
  166.   canUnload: function(compMgr)
  167.   {
  168.     return true;
  169.   }
  170. };
  171.  
  172. /**
  173.  * \class sbPlaylistReaderListenerFactory
  174.  * \brief
  175.  */
  176. var sbPlaylistReaderListenerFactory =
  177. {
  178.     createInstance: function(outer, iid)
  179.     {
  180.         if (outer != null)
  181.             throw Components.results.NS_ERROR_NO_AGGREGATION;
  182.  
  183.         if (!iid.equals(SONGBIRD_PLAYLISTREADERLISTENER_IID) &&
  184.             !iid.equals(Components.interfaces.nsIWebProgressListener) &&
  185.             !iid.equals(Components.interfaces.nsISupportsWeakReference) &&
  186.             !iid.equals(Components.interfaces.nsISupports))
  187.             throw Components.results.NS_ERROR_INVALID_ARG;
  188.  
  189.         return (new CPlaylistReaderListener()).QueryInterface(iid);
  190.     }
  191. }; //sbPlaylistReaderListenerFactory
  192.  
  193. /**
  194.  * \function NSGetModule
  195.  * \brief
  196.  */
  197. function NSGetModule(comMgr, fileSpec)
  198. {
  199.   return sbPlaylistReaderListenerModule;
  200. } //NSGetModule
  201.  
  202.