[haiku-development] New Diff to Media player

  • From: Fredrik Modéen <fredrik@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 18 Oct 2007 14:07:21 +0200 (CEST)

I hope my diffs aren't to small and that I should wait until making more
changes.

this one don't move unwanted files to media player play list when drag and
drop and probably also when open file.

prepared for handling Zeta play list. Can't open a original play list from
R5 if some one has MIME data from media player play list in BeOS R5  the
please send it to me :)

-- 
MVH
Fredrik Modéen
Index: Playlist.cpp
===================================================================
--- Playlist.cpp        (revision 22599)
+++ Playlist.cpp        (working copy)
@@ -22,7 +23,10 @@
 #include <debugger.h>
 #include <new.h>
 #include <stdio.h>
-#include <string.h>
+#include <String.h>
+#include <NodeInfo.h>
+#include <File.h>
+#include <Mime.h>
 
 #include <Autolock.h>
 #include <Directory.h>
@@ -275,8 +279,8 @@
        Playlist* playlist = add ? &temporaryPlaylist : this;
 
        entry_ref ref;
-       for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; 
i++)
-               AppendToPlaylistRecursive(ref, playlist);
+       for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; 
i++) 
+               AppendToPlaylistRecursive(ref, playlist);       
 
        playlist->Sort();
 
@@ -308,7 +312,11 @@
                while (dir.GetNextRef(&subRef) == B_OK)
                        AppendToPlaylistRecursive(subRef, playlist);
        } else if (entry.IsFile()) {
-               playlist->AddRef(ref);
+               if(_IsMediaFile(&entry))
+                       playlist->AddRef(ref);
+               else if(_IsPlayList(&entry)){
+                       //printf("Will be replaced with afunction handeling 
PlayList Files\n");
+               }
        }
 }
 
@@ -331,6 +339,50 @@
 }
 
 
+/*static*/ bool
+Playlist::_IsMediaFile(const BEntry *entry)
+{
+       BString mimeBString = _ReturnMiMEString(entry);
+       if(mimeBString != NULL){
+               BMimeType superType;
+        BMimeType fileType(mimeBString.String());        
+        
+        if (fileType.GetSupertype(&superType) != B_OK)
+               return false;
+                       
+        if (superType == "audio" || superType == "video")
+               return true;
+           else
+                       return false;
+       }else
+               return false;
+}
+
+
+/*static*/ bool
+Playlist::_IsPlayList(const BEntry *entry)
+{      
+       BString mimeBString = _ReturnMiMEString(entry);         
+       if(mimeBString != NULL && mimeBString.Compare("text/x-playlist") == 0)
+               return true;
+       else
+               return false;
+}
+
+
+/*static*/ BString
+Playlist::_ReturnMiMEString(const BEntry *entry)
+{
+       BFile file(entry, B_READ_ONLY);
+       BNodeInfo nodeInfo(&file);
+       char mimeString[B_MIME_TYPE_LENGTH];        
+       if (nodeInfo.GetType(mimeString) == B_OK)
+               return BString(mimeString);     
+       else
+               return NULL;
+}
+
+
 void
 Playlist::_NotifyRefAdded(const entry_ref& ref, int32 index) const
 {
Index: Playlist.h
===================================================================
--- Playlist.h  (revision 22599)
+++ Playlist.h  (working copy)
@@ -74,7 +75,7 @@
                        bool                            AddListener(Listener* 
listener);
                        void                            
RemoveListener(Listener* listener);
 
-                       // support functions
+                       // support functions                    
                        void                            AppendRefs(const 
BMessage* refsReceivedMessage,
                                                                        int32 
appendIndex = -1);
        static  void                            AppendToPlaylistRecursive(const 
entry_ref& ref,
@@ -82,6 +83,9 @@
 
 private:
                        static int                      playlist_cmp(const 
void* p1, const void* p2);
+                       static bool             _IsMediaFile(const BEntry 
*entry);
+                       static bool                     _IsPlayList(const 
BEntry *entry);
+                       static BString          _ReturnMiMEString(const BEntry 
*entry);
 
                        void                            _NotifyRefAdded(const 
entry_ref& ref,
                                                                        int32 
index) const;

Other related posts: