Fix a few bugs related to image loading (wrap it all in a try catch lol)
This commit is contained in:
		
							parent
							
								
									0135d84443
								
							
						
					
					
						commit
						e9a07b15da
					
				
					 3 changed files with 30 additions and 16 deletions
				
			
		
							
								
								
									
										11
									
								
								src/main.cpp
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								src/main.cpp
									
										
									
									
									
								
							|  | @ -191,14 +191,22 @@ int main(int argc, char *argv[]) { | ||||||
|     //     std::cout << *it << std::endl;
 |     //     std::cout << *it << std::endl;
 | ||||||
|     // }
 |     // }
 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |     double lasttime = 0.0; | ||||||
|     // Main game loop
 |     // Main game loop
 | ||||||
|     while (!WindowShouldClose() && |     while (!WindowShouldClose() && | ||||||
|            run) // Detect window close button or ESC key, or a quit from the menu
 |            run) // Detect window close button or ESC key, or a quit from the menu
 | ||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
|  |         if (GetTime() > lasttime+3 ) { | ||||||
|  |             lasttime = GetTime(); | ||||||
|  |             current_player.Refresh(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         BeginDrawing(); |         BeginDrawing(); | ||||||
|         ClearBackground(DARKGRAY); |         ClearBackground(DARKGRAY); | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|         // start ImGui content
 |         // start ImGui content
 | ||||||
|         rlImGuiBegin(); |         rlImGuiBegin(); | ||||||
| 
 | 
 | ||||||
|  | @ -246,9 +254,6 @@ int main(int argc, char *argv[]) { | ||||||
| 
 | 
 | ||||||
|         if (ImGui::Begin("Player Control")) { |         if (ImGui::Begin("Player Control")) { | ||||||
|             ImGui::Text("%s", current_player.GetIdentity().c_str()); |             ImGui::Text("%s", current_player.GetIdentity().c_str()); | ||||||
|             ImGui::Text( |  | ||||||
|                 "%s", |  | ||||||
|                 current_player.GetCurrentMetadata()["mpris:artUrl"].get<std::string>().c_str()); |  | ||||||
|             if (ImGui::Button("Prev")) { |             if (ImGui::Button("Prev")) { | ||||||
|                 current_player.Prev(); |                 current_player.Prev(); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -14,16 +14,17 @@ MprisPlayer::MprisPlayer(std::string servicename) { | ||||||
|     bus_connection = sdbus::createSessionBusConnection(); |     bus_connection = sdbus::createSessionBusConnection(); | ||||||
|     sdbus::ServiceName dest{servicename}; |     sdbus::ServiceName dest{servicename}; | ||||||
|     sdbus::ObjectPath objec{"/org/mpris/MediaPlayer2"}; |     sdbus::ObjectPath objec{"/org/mpris/MediaPlayer2"}; | ||||||
| 
 |     image_path_cache = "NULL"; | ||||||
|     PlayerProxy = sdbus::createProxy(dest, objec); |     PlayerProxy = sdbus::createProxy(dest, objec); | ||||||
|     mp2 = "org.mpris.MediaPlayer2.Player"; |     mp2 = "org.mpris.MediaPlayer2.Player"; | ||||||
|     playpause = "PlayPause"; |  | ||||||
|     Refresh(); |     Refresh(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MprisPlayer::PausePlay() { | void MprisPlayer::PausePlay() { | ||||||
|     auto method = PlayerProxy->createMethodCall(mp2, playpause); |     auto method = PlayerProxy->createMethodCall(mp2, sdbus::MethodName("PlayPause")); | ||||||
|     auto reply = PlayerProxy->callMethod(method); |     try { | ||||||
|  |         auto reply = PlayerProxy->callMethod(method); | ||||||
|  |     } catch (const std::exception& e) {} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MprisPlayer::Next() { | void MprisPlayer::Next() { | ||||||
|  | @ -35,7 +36,9 @@ void MprisPlayer::Next() { | ||||||
| 
 | 
 | ||||||
| void MprisPlayer::Prev() { | void MprisPlayer::Prev() { | ||||||
|     auto method = PlayerProxy->createMethodCall(mp2, sdbus::MethodName("Previous")); |     auto method = PlayerProxy->createMethodCall(mp2, sdbus::MethodName("Previous")); | ||||||
|     auto reply = PlayerProxy->callMethod(method); |     try { | ||||||
|  |         auto reply = PlayerProxy->callMethod(method); | ||||||
|  |     } catch (const std::exception &e) {} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::string MprisPlayer::GetIdentity() { | std::string MprisPlayer::GetIdentity() { | ||||||
|  | @ -46,18 +49,23 @@ std::unordered_map<std::string, sdbus::Variant> MprisPlayer::GetCurrentMetadata( | ||||||
|     return current_metadata; |     return current_metadata; | ||||||
| } | } | ||||||
| void MprisPlayer::Refresh() { | void MprisPlayer::Refresh() { | ||||||
|     identity = PlayerProxy->getProperty("Identity") |     try { | ||||||
|                    .onInterface("org.mpris.MediaPlayer2") |         identity = PlayerProxy->getProperty("Identity") | ||||||
|                    .get<std::string>(); |                        .onInterface("org.mpris.MediaPlayer2") | ||||||
|     current_metadata = PlayerProxy->getProperty("Metadata") |                        .get<std::string>(); | ||||||
|                            .onInterface("org.mpris.MediaPlayer2.Player") |         current_metadata = PlayerProxy->getProperty("Metadata") | ||||||
|                            .get<std::unordered_map<std::string, sdbus::Variant>>(); |                                .onInterface("org.mpris.MediaPlayer2.Player") | ||||||
|  |                                .get<std::unordered_map<std::string, sdbus::Variant>>(); | ||||||
|  |         if (current_metadata["mpris:artUrl"].get<std::string>() != image_path_cache) { | ||||||
|  |             image_path_cache = current_metadata["mpris:artUrl"].get<std::string>(); | ||||||
|  |             UpdateTexture(); | ||||||
|  |         } | ||||||
|  |     } catch (const std::exception& e) {} | ||||||
|     return; |     return; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MprisPlayer::UpdateTexture() { | void MprisPlayer::UpdateTexture() { | ||||||
|     auto metadata = GetCurrentMetadata(); |     std::string filename = image_path_cache; | ||||||
|     std::string filename = metadata["mpris:artUrl"].get<std::string>(); |  | ||||||
|     if (filename.length() > 0) { |     if (filename.length() > 0) { | ||||||
|         if (filename.c_str()[0] == 'f') { |         if (filename.c_str()[0] == 'f') { | ||||||
|             std::cout << "parsing as file" << std::endl; |             std::cout << "parsing as file" << std::endl; | ||||||
|  |  | ||||||
|  | @ -29,6 +29,7 @@ class MprisPlayer { | ||||||
|     sdbus::InterfaceName mp2; |     sdbus::InterfaceName mp2; | ||||||
|     sdbus::MethodName playpause; |     sdbus::MethodName playpause; | ||||||
|     RayTexture tex; |     RayTexture tex; | ||||||
|  |     std::string image_path_cache; | ||||||
|     explicit MprisPlayer(std::string servicename); |     explicit MprisPlayer(std::string servicename); | ||||||
|     void PausePlay(); |     void PausePlay(); | ||||||
|     void Refresh(); |     void Refresh(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue