Plone Audio
===========

Audio support in Plone now consists of taking the zope3 audio support
and wrapping it with a Plone integration layer.

We begin this process by creating a new instance of a file content
type.

  >>> id = self.folder.invokeFactory(self.file_type, 'testfile1')
  >>> testfile1 = self.folder[id]

By default, doing an IAudio adapter lookup on that file should fail since
its media properties have not yet been activated.

  >>> from p4a.audio.interfaces import IAudio
  >>> IAudio(testfile1)
  Traceback (most recent call last):
  ...
  TypeError: ('Could not adapt'...)

So the next step would be to actually activate the audio enhancements on
this file instance.

  >>> media_config = testfile1.restrictedTraverse('@@media-config.html')
  >>> media_config.media_activated
  False
  >>> media_config.media_activated = True
  >>> media_config.media_activated
  True
    
This is what the testfile looks like before adaptation to IAudio
  >>> testfile1
  <ATFile at /plone/Members/test_user_1_/testfile1>


Now adapting it should work fine.

  >>> IAudio(testfile1)
  <p4a.audio ATCTFileAudio title=...>

Lets do the same thing with a folder.  Since p4a.audio allows folders
to additionally be media enhanced (as audio containers).

  >>> id = self.folder.invokeFactory('Folder', 'testfolder1')
  >>> testfolder1 = self.folder[id]

So the next step would be to actually activate the audio enhancements on
this folder.

  >>> media_config = testfolder1.restrictedTraverse('@@media-config.html')
  >>> media_config.media_activated
  False
  >>> media_config.media_activated = True
  >>> media_config.media_activated
  True

Make sure the *IAudioFileProvider* adapter works on the folder.

  >>> from p4a.audio.interfaces import IAudioProvider
  >>> adapted = IAudioProvider(testfolder1)
  >>> adapted.audio_items
  []
  
This was interesting, but the adapted folder has no items.
Now we'll add something to that folder because we want to explore accessing view
attributes on the item from the context of the container (and we don't know 
how to do it!)
  
  >>> id = testfolder1.invokeFactory(self.file_type, 'testfile2')
  >>> testfile2 = testfolder1[id]

By default, doing an IAudio adapter lookup on that file should fail since
its media properties have not yet been activated.

  >>> from p4a.audio.interfaces import IAudio, IMediaPlayer, \
  ... IAudioDataAccessor, IPossibleAudio
  >>> IAudio(testfile2)
  Traceback (most recent call last):
  ...
  TypeError: ('Could not adapt'...)

So the next step would be to actually activate the audio enhancements on
this file instance.

  >>> media_config = testfile2.restrictedTraverse('@@media-config.html')
  >>> media_config.media_activated
  False
  >>> media_config.media_activated = True
  >>> media_config.media_activated
  True
    
This is what the testfile looks like before adaptation to IAudio
  >>> testfile2
  <ATFile at /plone/Members/test_user_1_/testfolder1/testfile2>

Now adapting it should work fine.

  >>> IAudio(testfile2)
  <p4a.audio ATCTFileAudio title=...>
  
And we can get to the audio data - which has no keys, because it was a 
fake file.

  >>> IAudio(testfile2).audio_data.keys()
  []
  
We can also get the single musicitem in a 
folder through the folder and 

(Rocky - this shows a bit of our thinking, last night. Sascha spent a 
couple of hours helping us get this far. We were not really happy with having
to find the widget with the path, in the way we did below. And of
course the doctest comparison line is a real disaster.)
  
  >>> audios = IAudioProvider(testfolder1).audio_items
  >>> from zope.component import queryAdapter
  >>> audio = audios[0]
  >>> field = IAudio['file'].bind(audio)
  >>> widget = queryAdapter(field, IMediaPlayer, name='audio/mpeg')
  >>> widget('/testfolder1/testfile2/file')
  '\n        <div class="mp3-player">\n            <object type="application/x-shockwave-flash"\n                    data="http://nohost/plone/++resource++flashmp3player/musicplayer.swf?song_url=/testfolder1/testfile2/file"\n                    style="margin-top: 2px"\n                    width="17" \n                    height="17">\n                    <param name="movie"\n                           value="http://nohost/plone/++resource++flashmp3player/musicplayer.swf?song_url=/testfolder1/testfile2/file"\n                    />\n            </object>\n        </div>\n        '

 
We know that Smart Folders are potential audio containers as well.  So we
should test those as well.

Need more permissions first to create smart folders, will adopt ``Manager``
role.

  >>> self.setRoles('Manager')

  >>> id = self.folder.invokeFactory('Topic', 'testtopic1')
  >>> testtopic1 = self.folder[id]
  
Make sure sure we can activate audio enhancements on this smart folder.

  >>> media_config = testtopic1.restrictedTraverse('@@media-config.html')
  >>> media_config.media_activated
  False
  >>> media_config.media_activated = True
  >>> media_config.media_activated
  True
