AlbumArtList->count()

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Pater
Posts: 15
Joined: Fri Jun 03, 2011 12:45 pm

AlbumArtList->count()

Post by Pater »

Hi

i'm creating a webinterface using PHP on the server side.
When using AlbumArtList->Count, i get an PHP-error stating:
Fatal error: Call to an member function count on a non-object.

I cant figure out where the problem lies.

I am using the following code:

Code: Select all

<?php

class player
{
	public $CPL;
	public $CurrentSong;
	public $isPlaying;
	
	function __construct()
	{
		global $comset;

		$this->objSDB 	 = new COM('SongsDB.SDBApplication', $comset);
		$this->MMPlayer = $this->objSDB->Player; 
		$this->MMTools  = new COM('SongsDB.SDBTools', $comset );
		
		$this->objSDB->ShutdownAfterDisconnect = false;
	}
	
	public function getCurrentPlayList()
	{
		if( $this->objSDB->Player->CurrentPlaylist->Count > 5 )
		{
			$numItems = $this->objSDB->Player->CurrentPlaylist->Count;
		} else {
			$numItems = 5;
		}
		
		for( $i = 0; $i < $numItems; $i++ )
		{
			$song = $this->objSDB->Player->CurrentPlaylist->Item($i);
			$this->CPL[$i]['songID'] 	= $song->SongID;
			$this->CPL[$i]['Artist'] 	= $song->Artist->Name;
			$this->CPL[$i]['Album'] 	= $song->AlbumName;
			$this->CPL[$i]['Title'] 	= $song->Title;
			$this->CPL[$i]['Image'] 	= $this->getAlbumArt( $song->Artist->Name, $song->AlbumName );
			unset( $song );
		}
	}
	
	public function getAlbumArt( $Artist, $AlbumName )
	{
		$file = "../ImageCache/".$Artist.DS.$AlbumName.'.jpg';
		$Album = $this->MMTools->AlbumByName( $Artist, $AlbumName );//->AlbumArt->Count;
		$AlbumArt = $Album->AlbumArt;
		$numItems = $AlbumArt->Count(); //THE ERROR OCCURS ON THIS LINE
		if( $numItems < 1 )
		{
			return "/ImageCache/NoAlbumArt.jpg";
		} elseif( ! file_exists( $file ) )
		{
			$tools = new tools;
			if( $image = $tools->createAlbumArtImage( $Artist, $AlbumName ) )
			{
				return $image; 
			}
		} else {
			return $file;
		}
	}
}

?>
Initiated by:

Code: Select all

$player = new player();
$player->getCurrentPlaylist();
I can't discover any problem in my code, if someone knows what wrong, please respond!!
Pater
Posts: 15
Joined: Fri Jun 03, 2011 12:45 pm

Re: AlbumArtList->count()

Post by Pater »

Forgot to mention: You can access the site through http://home.peterelzinga.eu/PHPJSinterface/

-edit: Site cannot be accessed anymore
Last edited by Pater on Tue Dec 20, 2011 5:00 pm, edited 4 times in total.
Pater
Posts: 15
Joined: Fri Jun 03, 2011 12:45 pm

Re: AlbumArtList->count()

Post by Pater »

got a bit further in debugging the problem:

when limiting the returned playlist to 5 items,
the error does not occur.

so the problem must be within the first IF statement in getCurrentPlayList(),
or the FOR statement
Pater
Posts: 15
Joined: Fri Jun 03, 2011 12:45 pm

Re: AlbumArtList->count()

Post by Pater »

Found the error.

If the album has no AlbumArt, the object AlbumArt->Count gives an error.
To my opinion this is a bug in the software, as it should (of course) return 0,
so i can check whether the SongListItem has AlbumArt

Anyone got an idea how i can check if the album has an image?
Pater
Posts: 15
Joined: Fri Jun 03, 2011 12:45 pm

Re: AlbumArtList->count()

Post by Pater »

Got a workaround for this problem:

Code: Select all

	public function getAlbumArt( $Artist, $AlbumName )
	{
		$file = "../ImageCache/".$Artist.DS.$AlbumName.'.jpg';
		$Album = $this->MMTools->AlbumByName( $Artist, $AlbumName );//->AlbumArt->Count;
		$AlbumArt = $Album->AlbumArt;

		if( method_exists( $AlbumArt, "Count" ) ) //Checks if the Count method exists. If not, the number
		{
			$numItems = $AlbumArt->Count();
		} else {
			$numItems = 0;
		}
		if( $numItems < 1 )
		{
			return "/ImageCache/NoAlbumArt.jpg";
		} elseif( ! file_exists( $file ) )
		{
			$tools = new tools;
			if( $image = $tools->createAlbumArtImage( $Artist, $AlbumName ) )
			{
				return $file; 
			}
		} else {
			return $file;
		}
	}
method_exists( $AlbumArt, "Count" ) Checks if the Count method exists. If not, the number of AlbumArt items is zero
mcow
Posts: 834
Joined: Sun Sep 21, 2008 9:35 pm
Location: Cupertino, California

Re: AlbumArtList->count()

Post by mcow »

Pater wrote:Found the error.

If the album has no AlbumArt, the object AlbumArt->Count gives an error.
To my opinion this is a bug in the software, as it should (of course) return 0,
so i can check whether the SongListItem has AlbumArt
Curious. When I tried this in Python (both in MM3 and MM4), I get a when I query that property on an empty list, I get 0.
Pater
Posts: 15
Joined: Fri Jun 03, 2011 12:45 pm

Re: AlbumArtList->count()

Post by Pater »

maybe the developers could look into this?
mcow
Posts: 834
Joined: Sun Sep 21, 2008 9:35 pm
Location: Cupertino, California

Re: AlbumArtList->count()

Post by mcow »

Count is not a method, it's a property.
Post Reply